Help with UserForms

M

mb

Seem to have a problem with this line:

UserForm1.ListBox1.AddItem .FoundFiles(i)

Entire Script:

Sub FindFiles()
With Application.FileSearch
.NewSearch
.LookIn = "D:\AllData\APICS"
.SearchSubFolders = True
.TextorProperty = "APICS Dictionary"
.MatchTextExactly = True
.Filename = "*.xls"
.Execute
For i = 1 to .FoundFiles.Count
UserForm1.ListBox1.AddItem .FoundFiles(i)
next i
End With
UserForm1.Show
End Sub

Any ideas?

Thanks,
mb
 
L

Leith Ross

Hello MB,

You should check that the .FoundFiles.Count is not zero. If it is I
suspect .FoundFiles(i) object returns a Null. The .AddItem method will
fail if the item is not a string.

Try this...


Code:
--------------------
Sub FindFiles()

With Application.FileSearch
.NewSearch
.LookIn = "D:\AllData\APICS"
.SearchSubFolders = True
.TextorProperty = "APICS Dictionary"
.MatchTextExactly = True
.Filename = "*.xls"
.Execute
For i = 1 to .FoundFiles.Count
If .FoundFiles.Count = 0 Then Exit Sub
UserForm1.ListBox1.AddItem .FoundFiles(i)
Next i
End With

UserForm1.Show

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top