Adding complex cross-reference

E

Eva

I tried searching for a solution to this, but I haven't been able to
hit the magic string of key words that might hit on a solution. I have
a table that lists the subsection number, the heading text, and the
page number for each subsection. Right now I'm doing it manually by
putting the cursor in the first cell, inserting a cross reference to a
paragraph number, tabbing to the next cell, inserting a cross reference
to paragraph text, and tabbing to the next cell, then inserting a cross
reference to a page. I turned on macro record and generated these two
blind alleys:

Sub Paragraph_CF()
'
' Paragraph_CF Macro
' Macro recorded 8/2/2006 by whitlev
'
Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdNumberRelativeContext, ReferenceItem:="1", _
InsertAsHyperlink:=True, IncludePosition:=False,
SeparateNumbers:=False, _
SeparatorString:=" "
Selection.MoveRight Unit:=wdCell
Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdContentText, ReferenceItem:="1",
InsertAsHyperlink:=True _
, IncludePosition:=False, SeparateNumbers:=False,
SeparatorString:=" "
Selection.MoveRight Unit:=wdCell
Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdPageNumber, ReferenceItem:="1",
InsertAsHyperlink:=True, _
IncludePosition:=False, SeparateNumbers:=False,
SeparatorString:=" "
Selection.MoveRight Unit:=wdCell
Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdNumberRelativeContext, ReferenceItem:="2", _
InsertAsHyperlink:=True, IncludePosition:=False,
SeparateNumbers:=False, _
SeparatorString:=" "
Selection.MoveRight Unit:=wdCell
Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdContentText, ReferenceItem:="2",
InsertAsHyperlink:=True _
, IncludePosition:=False, SeparateNumbers:=False,
SeparatorString:=" "
Selection.MoveRight Unit:=wdCell
Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdPageNumber, ReferenceItem:="2",
InsertAsHyperlink:=True, _
IncludePosition:=False, SeparateNumbers:=False,
SeparatorString:=" "
Selection.MoveRight Unit:=wdCell
Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdNumberRelativeContext, ReferenceItem:="2", _
InsertAsHyperlink:=True, IncludePosition:=False,
SeparateNumbers:=False, _
SeparatorString:=" "
Selection.MoveRight Unit:=wdCell
Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdContentText, ReferenceItem:="3",
InsertAsHyperlink:=True _
, IncludePosition:=False, SeparateNumbers:=False,
SeparatorString:=" "
Selection.MoveRight Unit:=wdCell
Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdPageNumber, ReferenceItem:="3",
InsertAsHyperlink:=True, _
IncludePosition:=False, SeparateNumbers:=False,
SeparatorString:=" "
Selection.MoveRight Unit:=wdCell
Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdNumberRelativeContext, ReferenceItem:="1", _
InsertAsHyperlink:=True, IncludePosition:=False,
SeparateNumbers:=False, _
SeparatorString:=" "
Selection.MoveRight Unit:=wdCell
Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdContentText, ReferenceItem:="1",
InsertAsHyperlink:=True _
, IncludePosition:=False, SeparateNumbers:=False,
SeparatorString:=" "
Selection.MoveRight Unit:=wdCell
Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdPageNumber, ReferenceItem:="1",
InsertAsHyperlink:=True, _
IncludePosition:=False, SeparateNumbers:=False,
SeparatorString:=" "
Selection.MoveRight Unit:=wdCell
End Sub

And then I tried this:
Sub CF()
'
' CF Macro
' Macro recorded 8/2/2006 by whitlev
'
Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdNumberRelativeContext, ReferenceItem:="72", _
InsertAsHyperlink:=True, IncludePosition:=False,
SeparateNumbers:=False, _
SeparatorString:=" "
Selection.MoveRight Unit:=wdCell
Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdContentText, ReferenceItem:="72",
InsertAsHyperlink:= _
True, IncludePosition:=False, SeparateNumbers:=False,
SeparatorString:= _
" "
Selection.MoveRight Unit:=wdCell
Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdPageNumber, ReferenceItem:="72",
InsertAsHyperlink:=True _
, IncludePosition:=False, SeparateNumbers:=False,
SeparatorString:=" "
Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdNumberRelativeContext, ReferenceItem:="73", _
InsertAsHyperlink:=True, IncludePosition:=False,
SeparateNumbers:=False, _
SeparatorString:=" "
Selection.MoveRight Unit:=wdCell
Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdNumberRelativeContext, ReferenceItem:="73", _
InsertAsHyperlink:=True, IncludePosition:=False,
SeparateNumbers:=False, _
SeparatorString:=" "
Selection.MoveRight Unit:=wdCell
Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdContentText, ReferenceItem:="73",
InsertAsHyperlink:= _
True, IncludePosition:=False, SeparateNumbers:=False,
SeparatorString:= _
" "
Selection.MoveRight Unit:=wdCell
Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdPageNumber, ReferenceItem:="72",
InsertAsHyperlink:=True _
, IncludePosition:=False, SeparateNumbers:=False,
SeparatorString:=" "
End Sub

But editing them to update from, say, "72" to "73" seems like it would
take longer than doing it manually. Surely someone else has had this
need before I did. Dare I hope there's a macro out there for this?

TIA--Eva Whitley
 
J

Jezebel

Take a deep breath, take a step backwards (bearing in mind that no-one here
has any previous knowledge of you, your document, or your intentions) and
explain what you want to end up with. It's not at all obvious (to me,
anyway) what you're trying to do.
 
E

Eva Whitley

Take a deep breath, take a step backwards (bearing in mind that no-one here
has any previous knowledge of you, your document, or your intentions) and
explain what you want to end up with. It's not at all obvious (to me,
anyway) what you're trying to do.

Sure. I have a large Word document, broken down into chapters. In
addition to a TOC, we have tables at the beginning of each chapter. The
tables have three columns: a paragraph number (outline numbered as 1,
1.1, 1.1.1, etc.), the text from the header, and the page number. So a
row in a table would look like this: 1.1.1 | Fixing a Hole in the Roof
| 2-1.

(The document in question is for USPS, BTW, for mail processing
equipment.)

If there some code out there that would automate this? Right now, as I
said, it's a process where I Insert==>Cross Reference==>Paragraph
number, tab to the next cell, Insert==>Cross Reference==>Paragraph
text, tab to the next cell, Insert==>Cross Reference==>Page number,
repeat any number of times, depending on how many subsections there are
in the chapter.

In the second bit of code, I noticed it was referencing numbers, and I
thought it would be an easy fix to copy & paste into a new Word
document, and then do a search and replace to up the number by one. As
I said, it seems like it would take the same amount of time as doing it
the way I have. Also, I'm not sure if this would work with variable
lengths of my chapters.

All this makes me wish I knew VBA better so I could make better macros,
rather than using macro record. But I guess that's a rant for another
time. --Eva Whitley
 
J

Jezebel

Why not just have a separate TOC for each chapter, as well as the master TOC
for the entire document?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top