Graham Mayor

... helping to ease the lives of Microsoft Word users.

Many people access the material from this web site daily. Most just take what they want and run. That's OK, provided they are not selling on the material as their own; however if your productivity gains from the material you have used, a donation from the money you have saved would help to ensure the continued availability of this resource. Click the appropriate button above to access PayPal.

Apply processes to a batch of Word documents

Elsewhere on this web site there are batch processes to perform a number of tasks on a range of documents. The add-in featured here below is intended to cover those processes that have hitherto not been included.

The original version of the add-in was inspired by an add-in from my old friend Greg Maxey, to which it bore only a superficial resemblance; however as so often happens when we share ideas, he wanted to get involved in the further development, so from Version 2,0 the add-in is a collaborative effort.

The version you see illustrated below is functionally similar to Greg's version, though the branding reflects our individual tastes with links to resources on our own sites.

As with all the add-ins from this site, it is presented as a Word template and is supplied in zipped format complete with installation instructions. When installed it will add a tab and a pair of buttons to the Word ribbon as shown below :

One of the processes, pre-configured in the add-in template, employs a table stored in the body of the document 'Find and Replace Pairs Table.docx' included in the zip file, and which may be accessed by opening the template for editing in Word. This document is normally stored in the user's documents folder,

Tracking changes would adversely affect some of the processes. Where tracking changes may be an issue, tracking is turned off while processing then restored to its original setting.

Versions of the add-in before version 3.9, employed a table in the add-in itself to enable the find and replace option using table pairs. It was felt that Microsoft's ever more intrusive security may prevent this table from being edited and saved by some users, and so from version 3.9, the table was provided in a separate document.

The document 'Find and Replace Pairs Table.docx' would normally be filed in the user's Documents folder, where the add-in will find it if present. If preferred it can be stored in any trusted folder that has read/write access, but then the first time that option is used, the add-in will prompt for its location (see illustration below).

The table is intended to be editable, providing user-configurable find and replace pairs of words or phrases. The table header row is ignored when processing the documents.

Entries included in the table must conform to Word's find and replace rules and, where the option is selected, the use of wildcards - See the dedicated page on the subject of Using Wildcards in Word's Find and Replace dialog.   

The add-in is intended for use with Word compatible documents and templates and is error trapped against inappropriate use.

This dialog allows documents in a selected folder (and optionally its sub-folders) to be processed, with one of a range of built-in processes. Where the active document has content, the add-in also offers the option to process that document (shown unavailable in the above illustration).


Important! The add-in will not allow the selection of the root of any accessible drive (see below). The potential for causing havoc is too great. I had considered allowing it with strong warnings, but frankly I couldn't think of a circumstance where it was desirable to be able to process the root of a drive, so I have blocked it and the text box will change colour to reinforce the error.

The textbox colour will also indicate whether a manually entered folder is a valid folder, showing pink when the folder does not exist, changing to green when it does.


The processes

  1. Convert date fields
  2. Find and replace
  3. Find and replace (with table defined pairs)
  4. Find and replace (with table defined formatting)
  5. Convert older format documents
  6. Replace smart quotes with plain quotes
  7. Convert to PDF
  8. Convert to PDF with PDFCreator (Only when PDFCreator 2.# is available. It may not work with later versions of PDF Creator)
  9. Replace plain quotes with smart quotes
  10. Add document password protection
  11. Remove document password protection
  12. Remove personal information
  13. User Defined Process

The main userform dialog has context sensitive help, available by clicking the help button:

Convert date fields

This function converts { DATE } fields to { CREATEDATE } fields retaining any formatting switch that may be applied or adding a switch from a large selection of date formatting switches, when no original switch is present. The original switch thus takes precedence over the selected date format.

Where { DATE } fields are locked against updating, they are not converted.

Time fields

Historically Word has also used the { TIME } field to display the system date from the PC, therefore the 'Convert dates' function also converts { TIME } fields to { CREATEDATE } fields. However in the case of { TIME } fields, the fields are only converted where there is a date formatting switch present and when the field is not locked against updating.

In documents where time fields are used for logging times and dates and then locked to preserve those times and dates, the function should not affect those fields, however the complexity of field construction can be such that you should use test the process using a copy of a document, before committing the process to run on a batch of files, to ensure that it provides the required results.

Find and replace

The option provides a function to find and replace one word or text with another where-ever they happen to be in the documents. The process includes an option to search for whole words only and/or the use of wildcards - see Replace using wildcards.

To apply case sensitive searches, set the wildcard option.

Find and replace with table defined pairs

Whereas the previous option provides for a single pair of words or phrases, the table option enables multiple searches to be performed on the same document. The table containing the pairs of words or phrases are stored in a document 'Find and Replace Pairs Table.docx' supplied with the add-in and may be accessed by opening the document in Word.

You may add to or change any of the entries below the header row of the table. Do not change the layout of the table or the filename of the document. The document would normally be saved in the user's Documents folder, where it will be found automatically. File it anywhere else and you will be prompted for the location. Save the document after making any changes to the table and before using it in conjunction with the process.

With regard to the three cells at the right hand end of the table (illustrated above). Enter Y in the WC column to indicate the use of a wildcard search. The code uses only the first letter to indicate whether to employ a wildcard search, so 'Yes' or 'yes' would be equally valid.

If wildcard is not used, enter 'Y' in the match whole word column 'WWO' to process whole word only.

Note: When a wildcard is used for a defined pair, match whole word is ignored

To omit the search pair from the process, enter 'Y' in the 'Omit' column. Thus the same table can be used for a variety of replacements.

The table can be edited directly from the option by clicking the 'Edit Table' button. This will open the table document for editing and close the userform.

Testing your search and replace strings in a document before committing to a batch process will save a lot of grief later.

Find and replace (with table defined formatting)

This works in essentially the same way as the previous 'Find and replace with table defined pairs' option, however in this case the found text is replaced with the formatted content of the second column of the table. This can be any legitimate format that can be applied to the text, and could, for example, include an in-line graphic.

When this option is used, the wildcard and whole word only selections in the table are ignored!
The find options:
MatchWildcards = False
MatchCase = True
MatchWholeWord = True
are used.

Convert to PDF

Uses the PDF creation function built into Word to save a batch of documents in PDF format. This function is not available for single documents as it is easier to simply save the document from Word.

Convert to PDF using PDFCreator

This function is not available for single documents as it is easier to simply print the document from Word to the PDFCreator driver.

PDF creation using the built-in PDF Converter is much faster than creation with PDF Creator, so unless you need the extra functionality offered by PDF Creator, I would advise the use of the built-in converter.

The process has been configured to use the current version of PDF Creator and will no longer work with version 1.7.3.

Note that this also includes PDF Architect, which is not required, and unless you want this application, I would recommend that you use the 'Expert' installation settings and uncheck PDF Architect. Note also that the installer will offer assorted plug-ins for your browser, that are certainly not required. Make sure you de-select these during the installation.

When converting to PDF format with PDFCreator the add-in additionally provides the option to engage PDF security measures. When the 'Continue' button on the main dialog is clicked, a second userform will open to offer that facility. Clicking 'Cancel' on this userform will cancel the whole process.

The items shown disabled in the following illustration become available when a Master Password is entered. If you don't want additional security measures then don't set a Master Password!

Currently the additional security options are only supported when the option PDF is checked. Should you check one of the other PDF format types, the dialog changes as shown below and any security settings entered are returned to their default values.

If you enter a Master Password and continue without setting options, you will see the following dialog. Click 'No' to set options or 'Yes' to continue without.

The PDF files are created in the same folder as the documents.

Smart Quotes

The add-in provides processes to convert straight quotes to English/US pattern smart quotes and vice versa. Note that international smart quotes are not provided for.

Add document password protection

This option provides for the addition of a common password to open the processed documents, with optionally the facility to add a password to modify the documents:

This option can be used to replace an existing password. If the 'Require password' check box is checked (see next illustration) documents that are password protected may be processed, and this option will ensure that the password dialog is presented.


Remove document protection

This option provides for the removal of common passwords from the processed documents

Remove personal information

This option allows users to remove personal information from the document's metadata before publishing the document. The process also optionally offers the options to 'Accept All Tracked Changes' and to 'Remove Comments'. When the 'Remove Comments' check box is left unchecked, the comments are anonymised.

Run a user defined process

This option for experienced users with some VBA programming knowledge, allows the running of a user configured macro.

The 'User Defined Process' option allows users with VBA experience to define and execute their own processing procedures. "The procedure must be a 'Function' of a boolean variable type, defined in a standard module located in the user's 'Normal' template.

It must include a document object variable as a single parameter, and a basic error handler.. e.g.

Function MacroName(oDoc as Document) As Boolean


Function MacroName(ByRef oDoc As Word.Document) As Boolean


A sample of the basic structure required is shown in the first macro code panel below:

Function MyUserDefinedProcess(oDoc As Document) As Boolean
On Error GoTo Err_Handler
'Do Something with oDoc here. e.g.,"
oDoc.Range.InsertAfter "Some Text"
MyUserDefinedProcess = True
Exit Function
Select Case Err.Number
'Case Is = "Your handled errors e.g., 5109"
Case Else
MyUserDefinedProcess = False
Resume lbl_Exit
End Select
End Function


The macro function must not close the document, as that is handled in the add-in code.

For a real world example you may wish to use the process to replace a company logo, or to add text to the document etc. e.g. The example shown below will change an autotext field in the header (first page header only if appropriate) from "MyLogo" to "MyNewLogo":

Function ChangeLogoBuildingBlock(ByRef oDoc As Word.Document) As Boolean
Dim oSection As Section
Dim oHeader As HeaderFooter
Dim oRng As Range
Dim fld As Field
On Error GoTo Err_Handler
Set oSection = oDoc.Sections(1)
If oDoc.PageSetup.DifferentFirstPageHeaderFooter = True Then
Set oHeader = oSection.Headers(wdHeaderFooterFirstPage)
Set oRng = oHeader.Range
For Each fld In oRng.Fields
If fld.Type = wdFieldAutoText Then
If InStr(1, fld.Code, "MyLogo") > 0 Then
fld.Code.Text = Replace(fld.Code.Text, "MyLogo", "MyNewLogo")
Exit For
End If
End If
Next fld
Set oHeader = oSection.Headers(wdHeaderFooterPrimary)
Set oRng = oHeader.Range
For Each fld In oRng.Fields
If fld.Type = wdFieldAutoText Then
If InStr(1, fld.Code, "MyLogo") > 0 Then
fld.Code.Text = Replace(fld.Code.Text, "MyLogo", "MyNewLogo")
Exit For
End If
End If
Next fld
End If
ChangeLogoBuildingBlock = True
Exit Function
ChangeLogoBuildingBlock = False
Resume lbl_Exit
End Function

To run the macro from the batch process add-in, enter "ChangeLogoBuildingBlock" in the dialog macro name text box:


Password protection (see also the sections above on adding and removing passwords)

The add-in will accommodate documents and templates which are password protected against opening, modification, and in the case of protected forms against editing by checking the 'Require password' check box and entering the common passwords for the documents in the password dialog.

Documents for which a password is missing or incorrect are not processed but logged for later reference.

A convenient oddity in the way Word VBA opens documents allows documents without password protection to be opened when a password that is not relevant to them is applied, thus the add-in will open documents that are not protected even though you set a password here.


Progress indication

Where the add-in is processing multiple documents from a folder or a folder and its sub folders, progress indicators provide information about the current status:

When all is done, any unprocessed files are logged by name, with their paths, in a document which is left on screen. This document is unsaved and can be disposed of when the information it contains has been assimilated.



- Click here to download the add-in



 Batch Processing

It is a common requirement for users to wish to apply similar information to a number of documents.

The add-in featured on this page will allow you to run a variety of processes, some built-in, others of your own design, on the currently active document, or on a folder containing documents, and, if required, any sub folders of that folder.

Some illustrations may not reflect the latest version number. The dialogs they contain are however similar to the latest version.