Contents - Index - Previous - Next


Page references for Microsoft Word files


In Microsoft Word, you can use a macro to insert Concordance-style page references automatically into a Word document, then copy the whole document to the Clipboard and make a concordance from it.  This can be particularly useful if you want an Index.

Here is how to do it in versions of Word from Word 97 to Word 2002:

In Word, go to Tools -> Macro -> Macros.  Type "ConcPageNums" (without the quotes) as the name of a new macro, then press the Create button. Microsoft Visual Basic should open with the macro editor.  

After the line which says "Macro created <today's date> by <your name>" and before the line "End Sub", insert the following lines by copying and pasting.

Dim count_
WordBasic.StartOfDocument
count_ = 1
WordBasic.EditBookmark "Temp", Add:=1
WordBasic.InsertField Field:=" PAGE \# " + Chr(34) + "'<P '#'>'" +Chr(34)
WordBasic.WW7_EditGoTo Destination:="+1"
While WordBasic.CmpBookmarks("\Sel", "Temp") <> 0
    WordBasic.EditBookmark "Temp", Add:=1
    count_ = count_ + 1
    WordBasic.InsertField Field:=" PAGE \# " + Chr(34) + "'<P '#'>'" +Chr(34) + "\*MERGEFORMAT"
    WordBasic.RepeatFind
Wend
WordBasic.EditBookmark "Temp", Delete:=1
WordBasic.MsgBox "Added page references to " + Str(count_) + " pages"


Make sure that no long line has been split or wrapped onto two lines when you have pasted. For example, there should be only four lines of text in the indented section between While and Wend: the third of those lines is very long, ending with "\*MERGEFORMAT"    

Now you can go to a Word document, choose Tools -> Macro -> Macros, choose ConcPageNums, and press Run. This will add the page references.

See your Word help for more on installing and using macros.  If any of this doesn't work, you should seek help from your local support person who specialises in Microsoft Office.  Your copy of Word may be set up to disallow macros.

______________________________________


Here is an older version of the macro for Word 6.0:

Sub MAIN
StartOfDocument
count = 1
EditBookmark "Temp", .Add
InsertField .Field = " PAGE \# " + Chr$(34) + "'<P '#'>'" + Chr$(34)
EditGoTo .Destination = "+1"
While CmpBookmarks("\Sel", "Temp") <> 0
EditBookmark "Temp", .Add
count = count + 1
  InsertField .Field = " PAGE \# " + Chr$(34) + "'<P '#'>'" +  Chr$(34)   + " \* MERGEFORMAT"
RepeatFind
Wend
EditBookmark "Temp", .Delete
MsgBox "Added page references to " + Str$(count) + " pages"
End Sub
______________________________________