|
|
|
|
|
|
Word
|
Process All Documents in a Specified Directory Folder
|
|
Ease of Use
|
Intermediate
|
Version tested with
|
|
Submitted by:
|
Steiner
|
Description:
|
Run your macro on all files in a specified folder.
|
Discussion:
|
You have a whole bunch of documents in a given directory and need to do a search & replace on all of them. Instead of opening them all manually, insert your search & replace call into this macro and let VBA do the work for you.
|
Code:
|
instructions for use
|
Sub ProcessAll(sPath As String)
Dim WdDoc As Document, sFile As String
sFile = Dir(sPath & "*.doc")
Do While sFile <> ""
Set WdDoc = Application.Documents.Open(sPath & sFile)
Debug.Print WdDoc.Name
WdDoc.Close wdDoNotSaveChanges
sFile = Dir
Loop
End Sub
|
How to use:
|
- Copy the code above.
- Create a new document.
- Hit Alt+F11 to open the Visual Basic Editor (VBE).
- From the menu, choose Insert-Module.
- Paste the code into the code window at right.
- Add the code that will perform the process you desire.
- Close the VBE.
|
Test the code:
|
- Create a directory, let's call it "C:\test\"
- Be sure to add the backslash at the end of the directory name in the code!
- Place several Word docs in there. (Password protection requires additional code; ask at the forum.)
- Hit Tools-Macro-Macros and double-click ProcessAll
|
Sample File:
|
No Attachment
|
Approved by Anne Troy
|
This entry has been viewed 155 times.
|
|