Finding files in a folder. Variable not defined error.
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 |
Finding files in a folder. Variable not defined error.
define it
Dim c As Range -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "Ayo" wrote in message ... 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 |
All times are GMT +1. The time now is 05:02 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com