Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Application-defined or object-defined error Please Help [email protected] Excel Discussion (Misc queries) 1 April 3rd 06 01:00 PM
Macro error : Application-defined or object-defined error Joe Excel Discussion (Misc queries) 3 January 27th 06 02:32 PM
how can I specific a folder with wildcard criteria and excel will import all the correct files in that folder? Raven Excel Discussion (Misc queries) 1 January 24th 06 03:28 PM
finding all empty excel files in a folder. jackm1 Excel Discussion (Misc queries) 4 July 20th 05 11:23 PM
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM


All times are GMT +1. The time now is 06:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"