Discussion:
Cross referencing a relative paragraph number
(too old to reply)
automandc
2005-03-08 00:07:03 UTC
Permalink
Here is a frustrating problem I would love to solve:

In a document of numbered paragraphs I would like to insert a cross
reference that always refers to the paragraph immediately before the
paragraph it is in. For example, if I have text like this:

52. Paragraph text.
53. Another Paragraph text.
54. More text, "and see the text in paragraph __"

I want the blank in paragraph 54 to be a cross reference to (54 - 1) (its
own paragraph minus one), so that even if I insert several paragraphs between
53 and 54, the blank still references the number of the paragraph immediately
preceeding its own.

[By way of explanation: In legal complaints it is standard to insert an
internal reference at the beginning of each legal count that says something
like "Plaintiff hereby repeats and realleges all of the averments in
paragraphs 1 to __ above as if set forth herein." It is possible to insert a
regular cross reference for the blank, but if you add any paragraphs between
counts, or reorder the counts then the cross reference doesn't point to the
correct paragraph anymore.]

If your readers can help me find a solution I would be most greatful!

Thanks in advance!
Jezebel
2005-03-08 00:38:39 UTC
Permalink
You could do it with SEQ fields, although this solution might be more
trouble than it is worth.

1. Instead of list numbering, use a SEQ field at the start of each
paragraph, eg { SEQ ParNum }.

2. To refer to the current paragraph - 1, use a calculation field: { = { SEQ
ParNum \c } - 1 }
Post by automandc
In a document of numbered paragraphs I would like to insert a cross
reference that always refers to the paragraph immediately before the
52. Paragraph text.
53. Another Paragraph text.
54. More text, "and see the text in paragraph __"
I want the blank in paragraph 54 to be a cross reference to (54 - 1) (its
own paragraph minus one), so that even if I insert several paragraphs between
53 and 54, the blank still references the number of the paragraph immediately
preceeding its own.
[By way of explanation: In legal complaints it is standard to insert an
internal reference at the beginning of each legal count that says something
like "Plaintiff hereby repeats and realleges all of the averments in
paragraphs 1 to __ above as if set forth herein." It is possible to insert a
regular cross reference for the blank, but if you add any paragraphs between
counts, or reorder the counts then the cross reference doesn't point to the
correct paragraph anymore.]
If your readers can help me find a solution I would be most greatful!
Thanks in advance!
automandc
2005-03-08 01:29:02 UTC
Permalink
Thanks, that is almost the answer. It definitely works, but it is no easier
than just inserting cross-references manually as a last step.

I refined your method by inserting a cross reference to the paragraph that
the field is in instead of using a "SEQ" field. This works if you change
make sure to use the \n switch in the REF field, rather than the \r. So,
here is an example that works:

{ = { REF _Ref97990013 \n} - 1}

Now, to complete the solution, I need a way to capture the "_Ref#####"
number programatically so that I don't have to manually enter a cross
reference. Is there a way to know what the _Ref ID is going to be for the
current paragraph?

Sheesh, if they would just allow a \c switch in the LISTNUM field, the
problem would be solved!
Post by Jezebel
You could do it with SEQ fields, although this solution might be more
trouble than it is worth.
1. Instead of list numbering, use a SEQ field at the start of each
paragraph, eg { SEQ ParNum }.
2. To refer to the current paragraph - 1, use a calculation field: { = { SEQ
ParNum \c } - 1 }
Post by automandc
In a document of numbered paragraphs I would like to insert a cross
reference that always refers to the paragraph immediately before the
52. Paragraph text.
53. Another Paragraph text.
54. More text, "and see the text in paragraph __"
I want the blank in paragraph 54 to be a cross reference to (54 - 1) (its
own paragraph minus one), so that even if I insert several paragraphs between
53 and 54, the blank still references the number of the paragraph immediately
preceeding its own.
[By way of explanation: In legal complaints it is standard to insert an
internal reference at the beginning of each legal count that says something
like "Plaintiff hereby repeats and realleges all of the averments in
paragraphs 1 to __ above as if set forth herein." It is possible to insert a
regular cross reference for the blank, but if you add any paragraphs between
counts, or reorder the counts then the cross reference doesn't point to the
correct paragraph anymore.]
If your readers can help me find a solution I would be most greatful!
Thanks in advance!
Jezebel
2005-03-08 02:07:43 UTC
Permalink
You're going to need to do some macro work to make this happen -- in which
case you're sort of back where you started from. The trouble is, the RefID
is a random number assigned only when insert the cross-reference (it's just
an arbitrary bookmark name: the underscore makes the name hidden by
default). But if you're doing that programmatically, you might as well just
use ordinary list numbering, then programmatically retrieve the paragraph
number and subtract one.

Once the paragraph has been bookmarked (by you or automatically by inserting
a cross-reference) you can retrieve the bookmark name using
Paragraph.Bookmarks(1).Name.
Post by automandc
Thanks, that is almost the answer. It definitely works, but it is no easier
than just inserting cross-references manually as a last step.
I refined your method by inserting a cross reference to the paragraph that
the field is in instead of using a "SEQ" field. This works if you change
make sure to use the \n switch in the REF field, rather than the \r. So,
{ = { REF _Ref97990013 \n} - 1}
Now, to complete the solution, I need a way to capture the "_Ref#####"
number programatically so that I don't have to manually enter a cross
reference. Is there a way to know what the _Ref ID is going to be for the
current paragraph?
Sheesh, if they would just allow a \c switch in the LISTNUM field, the
problem would be solved!
Post by Jezebel
You could do it with SEQ fields, although this solution might be more
trouble than it is worth.
1. Instead of list numbering, use a SEQ field at the start of each
paragraph, eg { SEQ ParNum }.
2. To refer to the current paragraph - 1, use a calculation field: { = { SEQ
ParNum \c } - 1 }
Post by automandc
In a document of numbered paragraphs I would like to insert a cross
reference that always refers to the paragraph immediately before the
52. Paragraph text.
53. Another Paragraph text.
54. More text, "and see the text in paragraph __"
I want the blank in paragraph 54 to be a cross reference to (54 - 1) (its
own paragraph minus one), so that even if I insert several paragraphs between
53 and 54, the blank still references the number of the paragraph immediately
preceeding its own.
[By way of explanation: In legal complaints it is standard to insert an
internal reference at the beginning of each legal count that says something
like "Plaintiff hereby repeats and realleges all of the averments in
paragraphs 1 to __ above as if set forth herein." It is possible to insert a
regular cross reference for the blank, but if you add any paragraphs between
counts, or reorder the counts then the cross reference doesn't point to the
correct paragraph anymore.]
If your readers can help me find a solution I would be most greatful!
Thanks in advance!
automandc
2005-03-08 03:41:04 UTC
Permalink
I confess that I am only a rank beginner at VBA. My biggest hurdle has been
figuring out how to "programmatically retrieve the paragraph number." I
understand the index property and can sorta figure out the listParagraph
collection, but what I can't figure out is how to find out the index of where
I already am (where the insertion point is).

I appreciate the help you have given so far though!

Thanks
Post by Jezebel
You're going to need to do some macro work to make this happen -- in which
case you're sort of back where you started from. The trouble is, the RefID
is a random number assigned only when insert the cross-reference (it's just
an arbitrary bookmark name: the underscore makes the name hidden by
default). But if you're doing that programmatically, you might as well just
use ordinary list numbering, then programmatically retrieve the paragraph
number and subtract one.
Once the paragraph has been bookmarked (by you or automatically by inserting
a cross-reference) you can retrieve the bookmark name using
Paragraph.Bookmarks(1).Name.
Post by automandc
Thanks, that is almost the answer. It definitely works, but it is no easier
than just inserting cross-references manually as a last step.
I refined your method by inserting a cross reference to the paragraph that
the field is in instead of using a "SEQ" field. This works if you change
make sure to use the \n switch in the REF field, rather than the \r. So,
{ = { REF _Ref97990013 \n} - 1}
Now, to complete the solution, I need a way to capture the "_Ref#####"
number programatically so that I don't have to manually enter a cross
reference. Is there a way to know what the _Ref ID is going to be for the
current paragraph?
Sheesh, if they would just allow a \c switch in the LISTNUM field, the
problem would be solved!
Post by Jezebel
You could do it with SEQ fields, although this solution might be more
trouble than it is worth.
1. Instead of list numbering, use a SEQ field at the start of each
paragraph, eg { SEQ ParNum }.
2. To refer to the current paragraph - 1, use a calculation field: { = { SEQ
ParNum \c } - 1 }
Post by automandc
In a document of numbered paragraphs I would like to insert a cross
reference that always refers to the paragraph immediately before the
52. Paragraph text.
53. Another Paragraph text.
54. More text, "and see the text in paragraph __"
I want the blank in paragraph 54 to be a cross reference to (54 - 1) (its
own paragraph minus one), so that even if I insert several paragraphs between
53 and 54, the blank still references the number of the paragraph immediately
preceeding its own.
[By way of explanation: In legal complaints it is standard to insert an
internal reference at the beginning of each legal count that says something
like "Plaintiff hereby repeats and realleges all of the averments in
paragraphs 1 to __ above as if set forth herein." It is possible to insert a
regular cross reference for the blank, but if you add any paragraphs between
counts, or reorder the counts then the cross reference doesn't point to the
correct paragraph anymore.]
If your readers can help me find a solution I would be most greatful!
Thanks in advance!
automandc
2005-03-08 08:13:02 UTC
Permalink
I took the opportunity to learn enough VBA for Word to make this work. Here
is my solution. Thanks for your help!

Sub AutoRefPrevPara()
' Inserts a nested field that automatically refers
' to the paragraph of the immediately preceding
' paragraph, even if the current paragraph changes number.
' To accomplish this it is necessary to identify a
' bookmark in the current paragraph, and if none exists
' then it creates a hidden bookmark.

If Selection.Paragraphs(1).Range.ListFormat.ListValue > 0 Then

i = Selection.Paragraphs(1).Range.Bookmarks.Count

If i = 0 Then
Do
r = Int((5999999 - 5000000 + 1) * Rnd + 5000000)
bmName = "_Ref" & r
Loop Until (ActiveDocument.Bookmarks.Exists(bmName) = False)
Selection.Paragraphs(1).Range.Bookmarks.Add Name:=bmName
End If

bmName = Selection.Paragraphs(1).Range.Bookmarks(1).Name

Application.ScreenUpdating = False
ActiveWindow.View.ShowFieldCodes = True
With Selection
.Fields.Add _
Range:=Selection.Range, _
Type:=wdFieldEmpty, _
Text:="REF " & bmName & " \n", _
PreserveFormatting:=False
.MoveLeft unit:=wdCharacter, Count:=1, Extend:=wdExtend
.MoveEnd unit:=wdCharacter, Count:=-1
.InsertBefore Text:="= "
.InsertAfter Text:="-1"
.Fields.Add _
Range:=Selection.Range, _
Type:=wdFieldEmpty, _
PreserveFormatting:=False
.Fields.Update
End With
ActiveWindow.View.ShowFieldCodes = False
Application.ScreenUpdating = True

Else
MsgBox ("You can only insert the auto reference in a numbered list.")
End If
End Sub
Post by Jezebel
You're going to need to do some macro work to make this happen -- in which
case you're sort of back where you started from. The trouble is, the RefID
is a random number assigned only when insert the cross-reference (it's just
an arbitrary bookmark name: the underscore makes the name hidden by
default). But if you're doing that programmatically, you might as well just
use ordinary list numbering, then programmatically retrieve the paragraph
number and subtract one.
Once the paragraph has been bookmarked (by you or automatically by inserting
a cross-reference) you can retrieve the bookmark name using
Paragraph.Bookmarks(1).Name.
Post by automandc
Thanks, that is almost the answer. It definitely works, but it is no easier
than just inserting cross-references manually as a last step.
I refined your method by inserting a cross reference to the paragraph that
the field is in instead of using a "SEQ" field. This works if you change
make sure to use the \n switch in the REF field, rather than the \r. So,
{ = { REF _Ref97990013 \n} - 1}
Now, to complete the solution, I need a way to capture the "_Ref#####"
number programatically so that I don't have to manually enter a cross
reference. Is there a way to know what the _Ref ID is going to be for the
current paragraph?
Sheesh, if they would just allow a \c switch in the LISTNUM field, the
problem would be solved!
Post by Jezebel
You could do it with SEQ fields, although this solution might be more
trouble than it is worth.
1. Instead of list numbering, use a SEQ field at the start of each
paragraph, eg { SEQ ParNum }.
2. To refer to the current paragraph - 1, use a calculation field: { = { SEQ
ParNum \c } - 1 }
Post by automandc
In a document of numbered paragraphs I would like to insert a cross
reference that always refers to the paragraph immediately before the
52. Paragraph text.
53. Another Paragraph text.
54. More text, "and see the text in paragraph __"
I want the blank in paragraph 54 to be a cross reference to (54 - 1) (its
own paragraph minus one), so that even if I insert several paragraphs between
53 and 54, the blank still references the number of the paragraph immediately
preceeding its own.
[By way of explanation: In legal complaints it is standard to insert an
internal reference at the beginning of each legal count that says something
like "Plaintiff hereby repeats and realleges all of the averments in
paragraphs 1 to __ above as if set forth herein." It is possible to insert a
regular cross reference for the blank, but if you add any paragraphs between
counts, or reorder the counts then the cross reference doesn't point to the
correct paragraph anymore.]
If your readers can help me find a solution I would be most greatful!
Thanks in advance!
Chuck
2005-03-08 11:19:02 UTC
Permalink
I think you may be making things a bit complicated for yourself. I work in a
legal environment and we use cross referencing all the time to keep cross
references pointing to the correct paragraphs regardless of
additions/deletions. For cross referencing to automatically update to
reflect added/deleted paragraphs you need to do two things:

1. Your paragraph numbers have to be based on a list template (outline
numbering), set in a style ("YourLevel 1", "YourLevel 2", etc).

2. You need to update all your fields (cross references are fields):
Ctl+a, then F9 is the manual way to do that.

You don't need macros for either of the above although you can create macros
to make both the above easier/more powerful. It seems to me that using
sequencing fields etc is re-inventing the wheel (the wheel being outline
numbering).

Bear in mind that outline numbering can get messy because IMHO it's buggy,
unless you work with named outline numbering lists (see Format > Bullets and
Numbering ... > Outline Numbered tab > Customize > More button > List num
field list name). There are other threads about how to solve problems with
outline numbering to make it more reliable -- you can search for "list
templates" both here and in google groups.

HTH
Chuck
Post by automandc
In a document of numbered paragraphs I would like to insert a cross
reference that always refers to the paragraph immediately before the
52. Paragraph text.
53. Another Paragraph text.
54. More text, "and see the text in paragraph __"
I want the blank in paragraph 54 to be a cross reference to (54 - 1) (its
own paragraph minus one), so that even if I insert several paragraphs between
53 and 54, the blank still references the number of the paragraph immediately
preceeding its own.
[By way of explanation: In legal complaints it is standard to insert an
internal reference at the beginning of each legal count that says something
like "Plaintiff hereby repeats and realleges all of the averments in
paragraphs 1 to __ above as if set forth herein." It is possible to insert a
regular cross reference for the blank, but if you add any paragraphs between
counts, or reorder the counts then the cross reference doesn't point to the
correct paragraph anymore.]
If your readers can help me find a solution I would be most greatful!
Thanks in advance!
automandc
2005-03-08 15:19:03 UTC
Permalink
Thanks. Note that I am not using a typical cross-reference like you would
for an "infra" or "supra" cite. In that case you want the target of the
reference to stay fixed. For instance, if I have a block of text, and later
want to refer to it, I can put in a "see supra" cite pointing to a bookmark
at the selected text. Then, even if that text moves to a different page, the
reference follows it.

In my instance it is a little bit different. Here we want to the reference
to always refer to the paragraph immediately before the one that it appears
in, even if new text is entered in between the current paragraph and the
previous one. So, if the text is in paragraph 25, and I cross reference to
paragraph 24, if I insert new paragraphs between 24 and 25 the reference
won't work. This happens frequently when you are drafting a complaint,
because you put in the rough outline of the claims with the standard
"reincorporate" language, but then later you add facts, new claims, expand on
the claims earlier, etc. So the paragraph where the "reincorporate" language
appears changes number, but the reference still needs to indicate that
paragraph number minus one.

A tricky little problem, but my Macro worked.
Post by Chuck
I think you may be making things a bit complicated for yourself. I work in a
legal environment and we use cross referencing all the time to keep cross
references pointing to the correct paragraphs regardless of
additions/deletions. For cross referencing to automatically update to
1. Your paragraph numbers have to be based on a list template (outline
numbering), set in a style ("YourLevel 1", "YourLevel 2", etc).
Ctl+a, then F9 is the manual way to do that.
You don't need macros for either of the above although you can create macros
to make both the above easier/more powerful. It seems to me that using
sequencing fields etc is re-inventing the wheel (the wheel being outline
numbering).
Bear in mind that outline numbering can get messy because IMHO it's buggy,
unless you work with named outline numbering lists (see Format > Bullets and
Numbering ... > Outline Numbered tab > Customize > More button > List num
field list name). There are other threads about how to solve problems with
outline numbering to make it more reliable -- you can search for "list
templates" both here and in google groups.
HTH
Chuck
Post by automandc
In a document of numbered paragraphs I would like to insert a cross
reference that always refers to the paragraph immediately before the
52. Paragraph text.
53. Another Paragraph text.
54. More text, "and see the text in paragraph __"
I want the blank in paragraph 54 to be a cross reference to (54 - 1) (its
own paragraph minus one), so that even if I insert several paragraphs between
53 and 54, the blank still references the number of the paragraph immediately
preceeding its own.
[By way of explanation: In legal complaints it is standard to insert an
internal reference at the beginning of each legal count that says something
like "Plaintiff hereby repeats and realleges all of the averments in
paragraphs 1 to __ above as if set forth herein." It is possible to insert a
regular cross reference for the blank, but if you add any paragraphs between
counts, or reorder the counts then the cross reference doesn't point to the
correct paragraph anymore.]
If your readers can help me find a solution I would be most greatful!
Thanks in advance!
Loading...