Cross References

J

jerem

FYI: VBA knowledge - low novice

Any way of designating the format of a Cross Reference

For example:

1) I'd like to be able to have my cross references come in underlined.
Someone suggested to me to underline the R in REF in the field code and that
does indeed work for that field code, however, every successive one comes in
without underlining. I've thought of searching for a field code (^d),
selecting highlight all items found in the Find and then hitting Ctrl U and
underline them all in one sweep however, I don't know how to single out
cross reference field codes only - I don't want my TOC field codes to be
underlined as well. I had a document with at least 100 cross refererences
which I had to manually underline - pain in the neck.

2) I'd like to be able to keep my prefixes of my cross refererences (i.e.,
Section 1.01) together when they come to the end of a line rather than have
Section on one line and 1.01 going to the next. I've been doing a search of
Section and a space and replacing these with Section and a hard space and
that works, but every time you update the fields the hard space gets wiped
out and you have to remember to do the search and replace all over again.

3) I've used the edit field button to select upper case for a cross
reference and the designation is visible in the field code, however, it seems
to be ignored even when deselecting the preserve formatting box. Don't know
what goes on with that????

Overall, rather than doing these patch jobs, just wondering if there is any
way to format a cross reference similar to the way one can format a style.

Any ideas, suggestions would be appreciated.
 
R

Russ

Jerem,
See below.
FYI: VBA knowledge - low novice

Any way of designating the format of a Cross Reference

For example:

1) I'd like to be able to have my cross references come in underlined.
Someone suggested to me to underline the R in REF in the field code and that
does indeed work for that field code, however, every successive one comes in
without underlining. I've thought of searching for a field code (^d),
selecting highlight all items found in the Find and then hitting Ctrl U and
underline them all in one sweep however, I don't know how to single out
cross reference field codes only - I don't want my TOC field codes to be
underlined as well. I had a document with at least 100 cross refererences
which I had to manually underline - pain in the neck.
Here's the answer to your first question, ** which was also answered in your
other message thread.** This sub underlines all crossreferences in the main
body and colors them blue. You can delete the blue font line or 'comment it
out' with an apostrophe if you don't want the blue color.
A consequence of using this formatting code is that the formatting
will also be there when printing the document.
You may have to combine my macro code with the suggested code at this
webpage for finding crossreferences in headers and footers.
http://word.mvps.org/faqs/customization/ReplaceAnywhere.htm

Public Sub UnderlineAllRefs()

Dim aField As Word.Field
Dim lngPlaceholder As Long

For Each aField In ActiveDocument.Fields
If aField.Type = wdFieldRef Then
If InStr(aField.Code.Text, "Charformat") = 0 Then
aField.Code.Text = aField.Code.Text & "\* Charformat"
End If
lngPlaceholder = InStr(aField.Code.Text, "REF")
aField.Code.Characters(lngPlaceholder).Font.Underline = True
aField.Code.Characters(lngPlaceholder).Font.Color = wdColorBlue
aField.Update
End If
Next aField

End Sub
2) I'd like to be able to keep my prefixes of my cross refererences (i.e.,
Section 1.01) together when they come to the end of a line rather than have
Section on one line and 1.01 going to the next. I've been doing a search of
Section and a space and replacing these with Section and a hard space and
that works, but every time you update the fields the hard space gets wiped
out and you have to remember to do the search and replace all over again.
Can you give an example?
How are you crossreferencing listnumbers? Are we talking about the same
thing? The listnumber should stay on one line if you set it up that way.
You use the menu Format/Bullets... Then outline numbered tab, then
customize, if you want.

If you are manually typing in the words literally 'Section 1.01' then you
are not letting Word do most of the work for you and TOC's can catch those
with the Heading styles.
Crossreference fields start with the word REF.
3) I've used the edit field button to select upper case for a cross
reference and the designation is visible in the field code, however, it seems
to be ignored even when deselecting the preserve formatting box. Don't know
what goes on with that????
Not sure what you are talking about here. Are you talking about styles or
hyperlinks? I thought you understood by what you said in question one, how
to format a crossreference. You format the R in REF and add \* Charformat.
Are you using the menu Insert/Crossrefences to do crossreferences? Maybe you
are talking about a different kind of field?
Overall, rather than doing these patch jobs, just wondering if there is any
way to format a cross reference similar to the way one can format a style.
Not that I know of, that is why we have shown how to manually format the R
in REF and add \* Charformat.
People have applied a style to the text before making it a crossreference,
etc. But as I mentioned above, they usually don't want to see that same
style when then go to print the document. Because crossreferences normally
are for moving around within a document and are not supposed to noticeable
when printing. On my MacWord they are shaded gray and have an optional popup
message when the mouse hovers over them; when clicked on, they move you to
the start of the object that was chosen when they were inserted. They are
plain text during printing, unless manually formatted before printing.
 
J

jerem

Hi Russ,
2) I'd like to be able to keep my prefixes of my cross refererences (i.e.,
Can you give an example?
How are you crossreferencing listnumbers? Are we talking about the same
thing? The listnumber should stay on one line if you set it up that way.
You use the menu Format/Bullets... Then outline numbered tab, then
customize, if you want.

In answer to your question above: the cross references were pulling from
Heading Styles and upon reading your answer I realized I should put the hard
space in the Heading style between the designation Section and the number
(never thought to do that simply because every Section numbering always
starts at the left margin and there is never a need to force these two to
stay together since they will never appear at the end of a line, however,
will style this way from hereonin in case cross references are elected
somewhere down the line (and that was indeed the case in this large document)
-- so #2 problem is solved. Thanks.

3) I've used the edit field button to select upper case for a cross
Not sure what you are talking about here. Are you talking about styles or
hyperlinks? I thought you understood by what you said in question one, how
to format a crossreference. You format the R in REF and add \* Charformat.
Are you using the menu Insert/Crossrefences to do crossreferences? Maybe you
are talking about a different kind of field?

In answer to your question about #3 above: Yes, everything in my original
question had to do with Cross Reerences. I selected three particular cross
references and needed those and only those to be uppercase because the
surrounding text was uppercase. When going into edit field I selected
uppercase, saw the instruction in the field code, but yet it would not
execute the instruction when selecting the whole document and clicking on
Update Field. Turns out I needed to highlight those individual field codes
and then say update and it worked so that was my error. Problem #3 solved.

1) Underlining cross refererences.

I shall try the code you game me. The solution of underscoring the R in the
REF field code does indeed work but when you have a document that has over
100 areas that have not been referenced yet, the idea of going into each
field code and underlining the R is equivalent to calling upon the cross
reference and then underlining the entire cross reference that you've just
pulled in which is what I ended up doing (and once you've done that the
formatting is preserved even upon updating fields). So what would have been
helpful and the only thing I could come up with is finding a way (after
putting all of the cross references in to underline them all in one sweep) to
search out that specific code -- only cross referencing field codes (not TOC
field codes because there was a large TOC in the document as well and I did
not want to have those codes underlined as well, although now in hindsight I
guess I could find every field code, underline them and then toggle the field
code of the TOC and deunderline the TOC field codes in one sweep).

A consequence of using this formatting code is that the formatting
will also be there when printing the document. Because crossreferences normally
are for moving around within a document and are not supposed to noticeable
when printing.

In response to your comments above -- in the legal arena cross references
are not used for navigating through a document - they are used to call
attention to previous sections in a contract, agreement, etc. and quite often
text is being moved around incessantly until the language is finalized and
ready to be sent out. In that time Sections 1.01 through 1.10, for example,
can now be Sections 4.01 through 4.10 in the final document - so they are
meant to be seen, they are meant to be specifically formatted and, most of
all, updated automatically (it is a tremendous task to manually keep track of
100 or so references) so the formatting issue is not a problem.

So, all of this comes back to one of the original question posed -- is there
any way when searching for a field code (^d) in the Find What Box to be field
specific (Cross Reference Field Code, TOC field code, etc.)

Thanks Russ for your help.
 
R

Russ

Jerem,
You're welcome.
As far as I know you can't manually use the find and replace to look for Ref
fields only. (except, if they had an unique style applied to them beforehand
and in that case you would search for the unique style.)
But various copies of my code could be adapted to underline, capitalize,
etc. ref field results. One copy could even throw up a msgbox asking which
of a limited number of choices are to be done to a selection (group) of ref
fields.
 
J

jerem

I haven't tried your code yet, but I think if the "Underlining All Refs" code
works that will do the trick and save a lot of time. I shall try it tonight
and let you know how it worked out. As always, appreciate your help.
 
R

Russ

Jerem,
I stumbled upon hyperlinks tonight and thought of your question about
formatting crossreferences to be underlined, etc.
What you probably remembered and intended to use, was not literally a
crossreference field with {REF...} but a hyperlink field with a small ell as
a switch to link to a bookmark within a document. { HYPERLINK \l "Test"}
Where "Test" is a name of a bookmark. A hyperlink will look underlined by
default.

A REF field just gives the starting jump-point text a gray background by
default, which doesn't show when printing.

Underlined hyperlinks do show when printing.

I wrote this subroutine to create a hyperlink out of selected text to a
bookmark within the current document. It then stores a couple of parameters
in document variables to use as default values when asking for input the
next time. To use subroutine, you must have bookmarks already in document.
Insertion point or selected text will be made into a hyperlink.

Sub InsertHyperlinkToBookmark()
Dim strBookMarkName As String
Dim strScreenTip As String
Dim strTextToDisplay As String
Dim aVar As Word.Variable
Dim num As Long
Dim myVar As String
Dim aRange As Word.Range
Dim strPrompt As String

If ActiveDocument.Bookmarks.Count = 0 Then
MsgBox "Insert some bookmarks, first."
Exit Sub
End If

strPrompt = "Bookmark To Jump To:" & vbCr & _
vbCr & "If left blank then bookmark list will appear." & vbCr & _
"A. Pick a bookmark from list" & vbCr & _
"B. Choose Goto button." & vbCr & _
"C. Choose Close button."

num = 0
For Each aVar In ActiveDocument.Variables
If aVar.Name = "BookMarkName" Then
num = aVar.Index
Exit For
End If
Next aVar
If num = 0 Then
strBookMarkName = InputBox(strPrompt, _
"What is the Bookmark Name?")
If strBookMarkName = "" Then
Set aRange = Selection.Range
With Dialogs(wdDialogInsertBookmark)
.Display
strBookMarkName = .Name
End With
aRange.Select
End If
ActiveDocument.Variables.Add Name:="BookMarkName", _
Value:=strBookMarkName
Else
strBookMarkName = Trim(InputBox(strPrompt, _
"What is the Bookmark Name?", _
ActiveDocument.Variables("BookMarkName").Value))
If strBookMarkName = "" Then
Set aRange = Selection.Range
With Dialogs(wdDialogInsertBookmark)
.Display
strBookMarkName = .Name
End With
aRange.Select
End If
ActiveDocument.Variables("BookMarkName").Value = strBookMarkName
End If


num = 0
For Each aVar In ActiveDocument.Variables
If aVar.Name = "ScreenTip" Then
num = aVar.Index
Exit For
End If
Next aVar
If num = 0 Then
strScreenTip = InputBox("ScreenTip:" & vbCr & _
"If blank of Cancel, then it will be bookmark name.", _
"What is the ScreenTip?", Trim(Selection.Range))
ActiveDocument.Variables.Add Name:="ScreenTip", Value:=strScreenTip
Else
strScreenTip = InputBox("ScreenTip:" & vbCr & _
"If blank of Cancel, then it will be bookmark name.", _
"What is the ScreenTip?", _
ActiveDocument.Variables("ScreenTip").Value)
ActiveDocument.Variables("ScreenTip").Value = strScreenTip
End If


strTextToDisplay = InputBox("Text To Display:" & vbCr & _
"Cancel or blank will be selected text." & vbCr & _
"Or if just insertion point, it will be bookmark name.", _
"What is the Text to Display?", Trim(Selection.Range))


ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, _
SubAddress:=strBookMarkName, ScreenTip:=strScreenTip, _
TextToDisplay:=Trim(strTextToDisplay)

'Hyperlink arguments are:
'Anchor - Required Object. The text or graphic that you want turned into a _
hyperlink.
'Address - Optional Variant. The address for the link. The address can be _
an e-mail address, an Internet address, or a file name. Note that Word _
doesn't check the accuracy of the address.
'SubAddress - Optional Variant. The name of a location within the _
destination file, such as a bookmark, named range, or slide number.
'ScreenTip - Optional Variant. The text that appears as a screen tip when _
the mouse pointer is positioned over the specified hyperlink. The _
default value is Address.
'TextToDisplay - Optional Variant. The display text of the specified _
hyperlink. The value of this argument replaces the text or graphic _
specified by Anchor.
'Target - Optional Variant. The name of the frame or window in which you _
want to load the specified hyperlink.

End Sub
 
J

jerem

Hi Russ,

No, I did intend to use literal Cross References. I know that people use
cross references for navigating through a document - hyperlinking to
different areas in a document, however, in a legal document you have, for
example.

Article I (with a title associated with
it) followed by
Section 1.01 (with a title associated with this paragraph) and then a
paragraph of text.
Section 1.02 (with a title associated with this paragraph) and then a
paragraph of text.
Section 1.03 - Section 1.10, etc. etc.
Then you'll have Article II - XII (for argument's sake) with let's say 10
sections in each Article.
Now within each of these Sections there may 5 references to other sections
all over the document. So, let's say Section 1.05 makes 5 different
references to language in 5 other sections. And Section 4.08 makes 10
different references to language in 10 other sections and so on and so forth
through the Sections in the document. (And an example of a reference will
read something like: "Time is of the Essence" shall mean ......... as
defined in Section 2.06, in this example the cross reference is placed as
Section 2.06).

Now, let's say some attorney comes along and rewrites the Agreement and
moves stuff all over the place. If you don't use cross references which are
linked through the Heading styles (all Articles are defined as Heading 1, all
Sections are defined as Heading 2's, all cross refererences are pulling their
numbering from both Heading 1 and Heading 2 (when the text reads Section 1.01
- the 1 before the period is the Heading 1 level numbering and the 01 is the
Heading 2 level numbering) what ends up happening is if you don't use cross
references which will conform all of your references with the new Section
numbering, you have to have a paralegal read through each and every line of
the document to find these references and conform the numbers manually. And
that is one pain in the you know what. So yes, I was literally talking about
Cross References - no one takes me literally on this website!! No, I'm just
kidding.

The issue of underlining is that the attorney wants the reference in the
paragraph to stand out and they do that through underlining. That problem
could have easily been addressed if the paragraph numbering -- Section 1.01
part of the paragraph was being underlined (similar to your advice about
putting the hard space in the style), however, they don't want that part to
be underlined - just the reference that is being made in the body of the
paragraph. So that's what presented a problem, however, your macro worked
great and solved that problem for me.

I did look over your code and that reminds me of the song "Things that make
you go Hmmm". It's quite interesting. I've got to give that some additional
thought!

Thanks for the additional info.
 
R

Russ

Jerem,
Thanks for the feedback and clarification. I can't take credit for the
hardspace idea because it wasn't mine.
 

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