View Single Post
  #2   Report Post  
Jay Freedman
 
Posts: n/a
Default

On Sun, 01 May 2005 00:40:25 -0700, Max Moor
wrote:

Hi All,
I have a document I've written (160+ pages) that has lots of cross-
references in it to various headings in other parts of the document.
Statements like "see Boiling Rubber Chickens," where Boiling Rubber
Chickens is a heading elsewhere.

I've just about done the whole thing, and have started wishing I'd have
done cross-references like, "see Boiling Rubber Chickens, pg 63," where an
actual page number was included (so the reader doesn't have to refer to the
TOC or index everytime they want to look up the reference.

Throughout the document, I've formatted cross-references with a
particular style, so I have the ability to select all of them at once. I'm
just not sure what to do to change them to the other format once they are
selected. Is there a way?

- Max


Hi Max,

Unfortunately, it isn't quite so simple as changing the style, because
styles affect only formatting and not text. However, it can be done
with a macro. The idea is to find each cross-reference that has the
specific style, and add after it the text ", pg " followed by a
PAGEREF field pointing to the same heading.

Use the instructions at http://www.gmayor.com/installing_macro.htm to
put this macro into either Normal.dot or the template your document is
based on, if that's diferent. In the .Style line, change the item in
quotes to the name of the style you used on your cross-references. Run
the macro only once on the document -- if you run it a second time on
the same document, it will add a second ", pg xx" to each reference.

Sub AddPageRefs()
Dim oRg As Range, oIns As Range
Dim strCode As String
Dim fldPg As Field

Set oRg = ActiveDocument.Range
oRg.TextRetrievalMode.IncludeFieldCodes = True
With oRg.Find
.Forward = True
.Format = True
.Style = ActiveDocument.Styles("Emphasis")
.Text = "^d REF"
Do While .Execute
strCode = oRg.Fields(1).Code.Text
Set oIns = oRg.Duplicate
With oIns
.Collapse wdCollapseEnd
.Text = ", pg "
.Collapse wdCollapseEnd
Set fldPg = ActiveDocument.Fields.Add( _
Range:=oIns, Type:=wdFieldEmpty)
fldPg.Code.Text = " PAGE" & LTrim(strCode)
fldPg.Update
End With
Loop
End With
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org