Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Application-defined or object-defined error Please Help | Excel Discussion (Misc queries) | |||
Macro error : Application-defined or object-defined error | Excel Discussion (Misc queries) | |||
how can I specific a folder with wildcard criteria and excel will import all the correct files in that folder? | Excel Discussion (Misc queries) | |||
finding all empty excel files in a folder. | Excel Discussion (Misc queries) | |||
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? | Excel Worksheet Functions |