Finding files in a folder. Variable not defined error.

A

Ayo

I am getting a variable not defined error on this line "For Each c In
lstrng.Cells" and I can't figure out what that means. Any ideas?

Set lstrng = Range("A2:A" & Range("A2").End(xlDown).Row)
Set fs = Application.FileSearch

'Use Microsoft Scripting runtime.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.getFolder(UserForm1.txtFolder.Value)

'Check type of file in the folder and open file.
For Each c In lstrng.Cells
c.Activate
If c <> "" Then
With fs
.LookIn = f
.SearchSubFolders = True
.Filename = c.Value
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
c.Offset(0, i + 1).Value = .FoundFiles(i)
Next i
Else
'MsgBox "There were no files found."
End If
End With
ElseIf c = "" Then
Exit For
End If
Next
 
B

Bob Phillips

define it

Dim c As Range

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

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