Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need to perform the same macro to multiple xls files in VB2005 Exp

How do I "loop" through multiple files in a folder to perform the same task
to each file?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Need to perform the same macro to multiple xls files in VB2005 Exp

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" wrote in message
...
How do I "loop" through multiple files in a folder to perform the same
task
to each file?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Need to perform the same macro to multiple xls files in VB2005 Exp

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" wrote in message
...
How do I "loop" through multiple files in a folder to perform the same
task
to each file?



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
Run Macro on multiple files LoriH Excel Discussion (Misc queries) 4 September 25th 08 07:08 AM
Macro: Filter Multiple header then extract to Multiple Files [email protected] Excel Discussion (Misc queries) 9 December 8th 06 10:44 PM
Combination chart using VB2005 Ventuspilot Charts and Charting in Excel 2 November 16th 06 01:34 AM
Learning VB6 or VB2005? DTTODGG Excel Programming 3 December 22nd 05 04:19 PM
Import multiple files macro can't find files Steven Rosenberg Excel Programming 1 August 7th 03 01:47 AM


All times are GMT +1. The time now is 11:20 AM.

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

About Us

"It's about Microsoft Excel"