Cross referencing a relative paragraph number

A

automandc

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!
 
J

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 }
 
A

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,
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!

Jezebel said:
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 }




automandc said:
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!
 
J

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.





automandc said:
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!

Jezebel said:
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 }




automandc said:
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!
 
A

automandc

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

Jezebel said:
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.





automandc said:
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!

Jezebel said:
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 }




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!
 
A

automandc

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

Jezebel said:
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.





automandc said:
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!

Jezebel said:
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 }




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!
 
C

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
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
 
A

automandc

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.

Chuck said:
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


automandc said:
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!
 

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