One of the frustrations with Author-it AfterPublish macros is debugging them. Especially if you have a large number of macros. Something goes wrong, but you do not know what the macro was doing at the time it died. Or you are just getting unexpected results and you suspect maybe a variable is set incorrectly.

If you are writing a macro to run over a normal Word document (for example, by clicking a button on the toolbar), it is fine to just put debugging messages throughout the code using the MsgBox function. For example:

MsgBox ("Number of pages in document: " &

However, when running Author-it AfterPublish macros, you do not want message boxes popping up during publishing (especially if you have set up automated publishing jobs).

The solution I have come up with for this problem is a couple of simple macros that output debugging messages to a log file. You simply call a macro with the debugging message as the parameter. Using the example from above you would use:

Logs.WriteLog ("Number of pages in document: " & 

The WriteLog macro writes the message passed to the macro to the log file and prefixes it with the current date and time. By default, the log file is written to the publishing folder and has the same name as the published Word document with a .log extension (although this can be overridden).

Installing and getting it working

To install the log file macros:

  1. Download the Logs.bas VBA module from here.
  2. Open your Word publishing template.
  3. Open the VBA editor (in Word 2007/2010, on the Developer tab click the Visual Basic button).
  4. From the File menu select Import File...
  5. Browse to and select the Logs.bas file downloaded in step 1.
  6. Save your template.

You are now ready to write to log files. As shown above, call the Logs.WriteLog macro and pass any string as the parameter. For example:

Author-it log file example

The resultant log file will look something like this:

Author-it log file example output


  • Writing to log files can degrade the performance of AfterPublish macros (because it increases the number of file I/O operations). You can turn logging off by setting the LogActive constant (near the top of the Logs module) to 'False':
Public Const LogActive = False
  • You can change the name of the log file by calling SetLogFileName and passing the new file name (you must also include the full path). For example:
Logs.SetLogFileName (ActiveDocument.Path & "\" & "AfterPublish.log")

Eliminate repetitive, mundane, and time-consuming tasks when publishing from Author-it Cloud

Find out more

Segue Consulting

Providing professional technical communication, Author-it consulting, and online communication services.

We are one of only two Author-it certified consultants in Australia.

Follow hamishblunck on Twitter