How do I "loop" through multiple files in a folder to perform the same task
to each file?
How do I "loop" through multiple files in a folder to perform the same task
to each file?
try something like
Sub x()
strFolder = "c:\"
If Right(strFolder, 1) <> "\" Then strFolder = strFolder & "\"
f = Dir(strFolder & "*.xls")
Do While f <> ""
Set wb = Workbooks.Open(strFolder & f)
Debug.Print wb.Worksheets(1).Name 'do stuff - wb will be the
workbook object
wb.Close
f = Dir()
Loop
Set wb = Nothing
End Sub
don't forget to turn off screen updating
rgds - voodooJoe
"Jhcorsair" <Jhcorsair@discussions.microsoft.com> wrote in message
news:F43CC4B3-81B9-4EF3-9002-D0F561A1CE1D@microsoft.com...
> How do I "loop" through multiple files in a folder to perform the same
> task
> to each file?
try something like
Sub x()
strFolder = "c:\"
strFileType = "xls"
If Right(strFolder, 1) <> "\" Then strFolder = strFolder & "\"
f = Dir(strFolder & "*." & strFileType)
Do While f <> ""
Set wb = Workbooks.Open(strFolder & f)
Debug.Print wb.Worksheets(1).Name 'do stuff - wb will be the
workbook object
wb.Close
f = Dir()
Loop
Set wb = Nothing
End Sub
remember to turn off screen updating
rgds- voodooJoe
"Jhcorsair" <Jhcorsair@discussions.microsoft.com> wrote in message
news:F43CC4B3-81B9-4EF3-9002-D0F561A1CE1D@microsoft.com...
> How do I "loop" through multiple files in a folder to perform the same
> task
> to each file?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks