Running macros for a number of files in a directory

bhanware

New Member
Joined
Nov 18, 2005
Messages
3
I have some tab delimited text files.
I have recorded a macro for file operation in excel.
But I have to open each file and run macro for it and then save it.
Is there any method by which I can run the macro for all the files in a folder and save them.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
you can use the Workbook.Open command to open the files one by one before running your macro.
 
Upvote 0
I have some files in a folder say 100. I have to perform some operation in each file. Now I don't want to open each file, running the macro and save it. Is there anything like batch processing for all files sothat the macro opens each file, performs operations and save them.
 
Upvote 0
With the Dir command, you can get a list of all files in the directory.

Code:
    a = Dir("*.xls")
    While a <> ""
        Debug.Print a
        a = Dir
    Wend

you can perform any actions with the file name, like replacing debug.print with workbooks.open(a)

hope this helps.
 
Upvote 0

Forum statistics

Threads
1,214,615
Messages
6,120,538
Members
448,970
Latest member
kennimack

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top