Avoiding name and original layout in cross references

O

Ogier

In some of my documents I have many equations, tables and figures which I
wish to refer to. I insert then with macros and use the following numbering
layouts:

Equations: (3)
Tables: *Table 5* **Table caption**
Figures: *Figure 7* Description of figure

where *...* indicates bold text and **...** indicates bold text and
increased font size. I use fields to insert numbers, like

Set fld = rng.Fields.Add(Range:=rng, Text:="SEQ Figure \* ARABIC", _
PreserveFormatting:=False)
Set rng = fld.Result


They all duly appear in the cross reference dialog box.

Now I would like to have references like this one, a somewhat extreme case
:) :

"Using equation (3) on page 11 we get the results shown in tables 5 and 6 on
page 13 and illustrated in figure 7 on page 14."

But using the cross reference box, what I get is this:
"Using equation (3 on page 11 we get the results illustrated in *Table 5*
and *Table 6* on page 13 and illustrated in *Figure 7* on page 14."

So the page references are OK, but the other references are flawed, because
1) the text or paranthesis preceding the number is included and 2) the
original layout is retained.

In the case of figures the cross reference dialog box allows references to
"Complete caption", "Only name and number", "Only text", "Page",
"Above/below" (retranslated from my Danish version). I sorely miss "Number
only"!

I can remove the formating and adjust the spelling manually after the
insertion, but that is cumbersome.

Have I overlooked something or is this another case of the Microsoft "We
know what you want" syndrome?

Best wishes
Holger Nielsen
 
D

DaveLett

When you insert your cross references select "Only name and number" for all
three. When you are ready to update the cross references, use the following
routine:

Dim lFld As Long
For lFld = ActiveDocument.Fields.Count To 1 Step -1
With ActiveDocument.Fields(lFld)
If .Type = wdFieldRef Then
If InStr(1, .Code, "Arabic") = 0 Then
.Code.Text = .Code.Text & "\* Arabic "
End If
End If
End With
Next lFld

Caveat: If you're using other REF fields, then this might cause some
problems, but we can do more branching to take care of that.

HTH,
Dave
 
O

Ogier

DaveLett said:
When you insert your cross references select "Only name and number" for all
three. When you are ready to update the cross references, use the following
routine:

Dim lFld As Long
For lFld = ActiveDocument.Fields.Count To 1 Step -1
With ActiveDocument.Fields(lFld)
If .Type = wdFieldRef Then
If InStr(1, .Code, "Arabic") = 0 Then
.Code.Text = .Code.Text & "\* Arabic "
End If
End If
End With
Next lFld

Caveat: If you're using other REF fields, then this might cause some
problems, but we can do more branching to take care of that.
I have made a test document containing
1) two figures and one table inserted using Word's buttons on the "Insert"
ribbon
2) two figures inserted with my own macro
3) references to these using the "Only name and number" option as you
suggested.

When I run your code nothing seems to happen. Isn't the only action it
performs to insert "\*Arabic" if it isn't there already? But it is, the
..Code.Text looks like there lines:
REF _Ref238638254 \h \* Arabic
REF _Ref238638202 \h \* Arabic

So I don't understand the purpose of your code.

Another problem turns up:
Word's own figure and table captions are set in light blue and reduced size.
The references to them are *not* formatted (I wonder how that is avoided),
but they are still capitalized ("Figure 1").
Does this mean that it is impossible to have normal language references like
"see figures 4 and 5", but one must accept "see Figure 4 and Figure 5"? I can
change the captions manually to lower case and plural, but when I update
(Ctrl-A and F9) I am back to what Word thinks is the way to do it.

Thank you for your response!

Holger
 
D

DaveLett

Hi Holger,
Sorry, I left out the update method (see below).

Dim lFld As Long
For lFld = ActiveDocument.Fields.Count To 1 Step -1
With ActiveDocument.Fields(lFld)
If .Type = wdFieldRef Then
If InStr(1, .Code, "Arabic") = 0 Then
..Code.Text = .Code.Text & "\* Arabic "
..Update
End If
End If
End With
Next lFld

By adding the "\* Arabic" switch to your field code, the result is a number
only. Therefore, you can type any text that you want before and after. For
example, you can type "see figures {fld} and {fld}", which should solve your
capitalization problem, too.

HTH,
Dave
 

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