Hi guys,
I tried Graham's suggestion, and I didn't get any errors -- it seemed
to
run
fine. But also the character format wasn't sticky. As soon as I change
to
Print View, or convert to PDF, the PageRef fields revert back to the
plain
text style. Is there something else that needs to be added to make the
character format sticky?
Thanks,
Kate
:
1. Hmmm. I tested this a few times using cross references to Figures
and
occasionally got the error - but more often than not I didn't. When
inserting pageref fields, either manually or via the Cross References
dialog, I did not get the error, and the macro code I modified has
worked
every time - I just tested it again to make sure. Then forced an
update
to
make sure there was no error. In fact I stole your code for my own use
as
it
was more efficient than the one I was using to change mergeformat to
charformat
Do you still get the error if you add quotes around the referenced
item?
2.If you format the entire range then the charformat switch should
cause
that range formatting to be adopted (which I thought was the
requirement).
the mergeformat field, in theory at least, should cause it to retain
the
formatting of the bookmark being referred to.
3. I did not get that error when I converted to PDF (Acrobat 7 -
patched
to
date and using the add-in tools to create the pdf) but if you are
getting
an
error when you update the field, that would account for it as the
fields
will update as part of the 'print' process. Unfortunately I cannot
produce
the error message consistently enough to bottom the problem,
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Dave Lett wrote:
Hi Graham,
I have found two issues with using CHARFORMAT and was wondering if
you could shed some light on them.
1) It appears that you cannot use CHARFORMAT when inserting a
PAGEREF
field through the Insert Cross References dialog box. That is,
CHARFORMAT appears to only be compatible with a PAGEREF field that
points to a bookmark. When I update the PAGEREF field that is a
crosss reference, Word displays Error! Unknown switch argument. as
the result.
2) The CHARFORMAT switch takes the formatting of the first letter of
the field that it appears in, which means that if you format the
result range and update the field, then the field will lose the
formatting that you applied. To make the format stick, you have to
apply the formatting to the "P" in the PAGEREF field (in this case)
to make the formatting stick.
Finally, I'm getting some strange results after converting to PDF:
PAGEREF _Ref147109471 \h \* CHARFORMAT
Error! Unknown switch argument.
PAGEREF _Ref147109471 \h \* MERGEFORMAT
[NO RESULT!! It's there in Word, but disappears upon conversion]
PAGEREF _Ref147109471 \h
1 [Formatted properly, formatting applied to result]
PAGEREF _Ref147109471 \h MERGEFORMAT
1 [Formatted properly, formatting applied to result, but notice that
"\*" is not included]
PAGEREF myHeading \* CHARFORMAT
1 [Formatted properly, formatting applied to "P" of PAGEREF]
PAGEREF myHeading \* MERGEFORMAT
1 [Formatted properly, formatting applied to result]
Dave
I suspect that it would be better to remove the MERGEFORMAT switch
and adda CHARFORMAT switch instead which will allow the field to
take on formatting applied to the field. The following modification
should do that. Dim iFld As Integer
For iFld = ActiveDocument.Fields.Count To 1 Step -1
With ActiveDocument.Fields(iFld)
If .Type = wdFieldPageRef Then
If InStr(1, .Code, "MERGEFORMAT") <> 0 Then
.Code.Text = Left(.Code.Text, Len(.Code.Text) - 16)
&
_ " \* CHARFORMAT "
End If
If InStr(1, .Code, "CHARFORMAT") = 0 Then
.Code.Text = .Code.Text & " \* CHARFORMAT "
End If
.Result.Style = "URL"
End If
End With
Next iFld
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Dave Lett wrote:
Hi Kate,
You are probably applying the character format, but you probably
haven't made the field code so that formatting is "sticky". That
is,
you have to ensure that the field code includes the
PreserveFormatting switch. The following might solve your issue:
Dim iFld As Integer
For iFld = ActiveDocument.Fields.Count To 1 Step -1
With ActiveDocument.Fields(iFld)
If .Type = wdFieldPageRef Then
If InStr(1, .Code, "MERGEFORMAT") = 0 Then
.Code.Text = .Code.Text & " \* MERGEFORMAT"
End If
.Result.Style = "Legacy"
End If
End With
Next iFld
HTH,
Dave
Hi all,
I generate Word documents from AuthorIT (CM software), and
release
them in PDF format. I need an automated solution for formatting
PageRef fields. Currently, the PageRef fields come through in the
regular body text
format.
I want to change them to use a specific character style (in this
case, the style is called URL, which is blue like a hyperlink). I
have tried using a macro to this, and it seems to work in Normal
view. But when I change to Print Preview, or convert to PDF, the
PageRef fields revert back to plain text.
Is there a way to permanently change the PageRef field to use a
specific character style?
I'm using the following macro:
Dim myField As Field
For Each myField In ActiveDocument.Fields
If myField.Type =3D wdFieldHyperlink Or myField.Type =3D =
wdFieldPageRef Then
myField.Result.Style =3D ActiveDocument.Styles("URL")
End If
Next myField
What am I doing wrong?
Best regards,
Kate