Email this Page Log Support Call Send Feedback Print

Previous Topic

Next Topic

Book Contents

Book Index

Using Word Macros to Customize Your Word Output

After publishing your Word document, and provided you have Macros enabled, Author-it will automatically run the AfterPublish() macro if it exists in your template. If you have a piece of formatting you think Author-it doesn't do quite right, and it cannot be corrected in Author-it, this is the place to fix it!

For this example, we have added a function called AddCellFormatting() that adds borders to cells containing the paragraph style "Table Body Text - Borders".

  1. Add a style in Author-it called "Table Body Text - Border" (duplicate it off "Table Body Text") as follows:
    • Open the style "Table Body Text"
    • Select the Object > Duplicate menu
    • Set the Style Definition name to "Table Body Text - Borders"
    • Set the General Description to "Table Body Text - Borders"
    • Under the Document tab, set the Map To Style property to "Table Body Text - Borders"
  2. Find which Word template you are using to publish Word documents from. Open your Book and check the Word Template on the Document tab.

    Note: By default this will be called authorit.dot and is usually found in your Word Templates directory.

    • Create a copy of this file so that if anything goes wrong you can restore it later.
    • Open this file by right clicking on it and selecting Open.

      Note: double clicking will create a new .DOC file based on the template, which we don't want.

    • Add a style in your Word template by selecting the Format > Style menu
    • Select New
    • Set the Stylename to "Table Body Text - Borders"
    • Set based on to "Table Body Text" and tick "add to template"
  3. Save the style by selecting OK.
  4. Ensure that Macros are enabled (this also enables macros for all those nasty e-mail virii so if you have enough computers do this on a publishing computer you don't read your e-mail on)
  5. Make the following changes to your AfterPublish() Macro:
    • Display a list of macros by selecting Tools > Macros > Visual Basic Editor
    • Expand out the project tree and look for a module named Author-it (earlier versions of the AuthorIT.dot file did not include this module in which case you will need to add it)
    • Double Click the AfterPublish() subroutine, and modify as follows:

      Sub AfterPublish()

      AddCellFormatting "Table Body Text - Border"

      End Sub

  6. Add the following subroutine in as well:
Private Sub AddCellFormatting(StyleName As String)
' Searches through the document looking for every
' instance of the style "Table Heading" and ensures
' that the borders are turned on for the cells
' containing text in this style.
' Created by Derek Tomes AuthorIT 7-Dec-2001

On Error Resume Next
Dim cellInst As Cell

' Message to see if correctly added to template...
MsgBox "This message lets you know you have enabled macros" & _
" and added the AddCellFormatting function correctly" & _
" into your template, it can be removed now."

If Not ActiveDocument.Styles(StyleName).InUse Then
	' Gets to here if:
	' a) the style exists in the document but is not in use.
	' b) the style does not exist in the document.
	Err.Clear
	Exit Sub
End If
' Set the selection to the beginning of the document.
Selection.StartOf wdStory
With Selection.Find
    ' Search direction is forward.
    .Forward = True
    ' Clear any other previous search formatting.
    .ClearFormatting
    .Replacement.ClearFormatting
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    ' Search for the style indicating that the cell should have borders.

    .Style = ActiveDocument.Styles(StyleName)

    ' Search for every instance of this style.
    Do While .Execute
        ' Ensure that the selection is in a table.
        If Selection.Information(wdWithInTable) Then
            ' For each cell within the current selection.
            For Each cellInst In Selection.Cells
                ' Apply custom formatting here:
                ' To turn off any of these lines, remove or
                ' prefix with a single quote (') character.

                ' The following line adds a border around the selected cells...
                cellInst.Borders.Enable = True

                ' The following code line adds shading around the selected cells...
                ' to enable remove the single quote (') character at the beginning of the line:
                'cellInst.Shading.BackgroundPatternColor = wdColorGray10
            Next
        End If
        ' Move to the next paragraph 
        Selection.Move wdParagraph, 1
    Loop
End With

' Remove any undo history to prevent Word.doc bloat.
ActiveDocument.UndoClear
End Sub
Top of Page Email this Page Log Support Call Send Feedback Print