How do I run a macro on multiple documents?
Using Run with Temporary Options
- Go to Macros | Run with Temporary Options….
- Choose the macro you want to run in the Macro field.
- Check Run the macro against each opened document. Click Add… to add files that the macro should be run on.
- Click Run.
Using Advanced Open
- Go to File | Advanced Open….
- Check Run the macro against each opened document. Click the “…” button to open the macro that you want to use.
- Click on Select Files to Open…. Select the files that the macro should be run on.
Using Scripting.FileSystemObject
- You can iterate through files in a folder with
Scripting.FileSystemObject
.
#language = "JScript"
function MyFunc( sFileName ) // macro function to call
{
document.writeln( sFileName ); // Replace this with what you want to do with sFileName
}
var sFolder = "C:\\folder_with_files"; // a folder you want to search
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f = fso.GetFolder(sFolder);
var fc = new Enumerator(f.files);
for (; !fc.atEnd(); fc.moveNext()) {
MyFunc( fc.item().name );
}