Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Running Macro on many files

Hi,
I have about 50 files in a folder and I want to run my macro on each file.
Is there a way to automate this?
Any help would be appreciated.
Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 318
Default Running Macro on many files

Hi Sean,
Try this code

Sub ProcessAllFiles()

Dim sFile$
Const path = "C:\Temp\Temp1\"

sFile = Dir(path & "*.xls")
Do While sFile < ""
'the new workbook will become active
Workbooks.Open (path & sFile)
'run your macro here
'however make sure that the new workbook
'remains active throughout the macro
Macro1
ActiveWorkbook.Close savechanges:=True
sFile = Dir
Loop

End Sub

Alok Joshi
"Sean" wrote:

Hi,
I have about 50 files in a folder and I want to run my macro on each file.
Is there a way to automate this?
Any help would be appreciated.
Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Running Macro on many files

Thanks so much Alok.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default Running Macro on many files

Alok,

I've tried your code on one of my macros, but I cannot seem to get it to
work. I have tons of runlogs that are generated and would like to implement
your code. The runlogs are incremented by *.L0, *.L1, *.L2, etc. where the
number could be anywhere between 0 to 10. What did I do wrong in the code
below? If I step through the code, it just goes right over the While loop,
even if I do change a few files to *.xls.

Thanks,
<3 Matt

Sub ProcessAllFiles()

Dim sFile$
Const path = "C:\Temp\Temp1\"

sFile = Dir(path & "*.*")
Do While sFile < ""
Workbooks.Open (path & sFile)
HELO_Macro
ActiveWorkbook.Close savechanges:=True
sFile = Dir
Loop

End Sub


"Alok" wrote:

Hi Sean,
Try this code

Sub ProcessAllFiles()

Dim sFile$
Const path = "C:\Temp\Temp1\"

sFile = Dir(path & "*.xls")
Do While sFile < ""
'the new workbook will become active
Workbooks.Open (path & sFile)
'run your macro here
'however make sure that the new workbook
'remains active throughout the macro
Macro1
ActiveWorkbook.Close savechanges:=True
sFile = Dir
Loop

End Sub

Alok Joshi
"Sean" wrote:

Hi,
I have about 50 files in a folder and I want to run my macro on each file.
Is there a way to automate this?
Any help would be appreciated.
Thanks

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
Excel Files being opened on a Computer running Vista Daniel Excel Discussion (Misc queries) 1 February 9th 09 06:42 PM
Running a macro on mulitple files Chris Excel Programming 1 December 8th 04 11:02 PM
Excel files on local drives running from internet FillyFriend Excel Worksheet Functions 0 November 22nd 04 09:23 PM
Running .avi files David Excel Programming 8 May 19th 04 12:16 PM
running macros in downloaded files blueshot[_3_] Excel Programming 2 December 23rd 03 08:24 AM


All times are GMT +1. The time now is 10:32 PM.

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"