Find Replace references from whatever they were to italics

J

Janet A. Thompson

I have a document I want to be sure references for Appendix alpha-#, or
Exhibit #-#, or Table #-# or Figure #-# are italicized. And I have several
chapters to do this in. How to do? I do NOT want the actual caption on the
figure or table to pick up the italization but I want thses to retain their
figure or table title syles. Thanks
 
D

Doug Robbins - Word MVP

Use a macro containing the following code to add the \* charformat switch to
each of the cross reference fields and apply the Italic formatting to the
first letter of the field code which will cause the cross reference to be
displayed in Italic font:

Dim afield As Field, i As Long
With ActiveDocument
For Each afield In .Fields
If afield.Type = wdFieldRef Then
With afield.Code
If InStr(.Text, "_Ref") > 0 Then
.Text = .Text & " \* charformat"
For i = 1 To .Characters.Count
If UCase(.Characters(i)) = "R" Then
.Characters(i).Font.Italic = True
Exit For
End If
Next i
End If
End With
End If
Next afield
.Range.Fields.Update
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
J

Janet A. Thompson

I think this will work for the tables and figures, but the exhibits and
appendices are not put in with captioning and are not fields. I think I need
a simple Find and Replace for these but I don't know what it is? Does anyone
know?
 
M

macropod

Hi Doug,

I think the macro should check for any \h switches in the fields concerned, as they'll throw a wobbly unless the \h switch comes
after the Charformat switch.

It's probably a good idea to delete any Mergeformat switches too, as they tell Word to format the field differently than the
Charformat switch and having both might lead to conflicts.
 
D

Doug Robbins - Word MVP

The following code should take care of that.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
D

Doug Robbins - Word MVP

Hi Paul,

Just checked that and having the \* charformat at the end of the field
construction did not cause any problem with the functionality provided by
the \h switch.

By default, the REF _Ref fields do not have a \* mergeformat switch.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
macropod said:
Hi Doug,

I think the macro should check for any \h switches in the fields
concerned, as they'll throw a wobbly unless the \h switch comes after the
Charformat switch.

It's probably a good idea to delete any Mergeformat switches too, as they
tell Word to format the field differently than the Charformat switch and
having both might lead to conflicts.

--
Cheers
macropod
[Microsoft MVP - Word]


Doug Robbins - Word MVP said:
Use a macro containing the following code to add the \* charformat switch
to each of the cross reference fields and apply the Italic formatting to
the first letter of the field code which will cause the cross reference
to be displayed in Italic font:

Dim afield As Field, i As Long
With ActiveDocument
For Each afield In .Fields
If afield.Type = wdFieldRef Then
With afield.Code
If InStr(.Text, "_Ref") > 0 Then
.Text = .Text & " \* charformat"
For i = 1 To .Characters.Count
If UCase(.Characters(i)) = "R" Then
.Characters(i).Font.Italic = True
Exit For
End If
Next i
End If
End With
End If
Next afield
.Range.Fields.Update
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
M

macropod

Hi Doug,

I was testing this earlier with Word 2000, and found having the CHARFORMATswitch after the \h switch resulted in and error message.
Can't reproduce it right now, though.

Also, if you try changing the format of a REF field from the keyboard, Word (2000) automatically adds \* MERGEFORMAT to the field.
It seems this is just as likely to be an issue if one applies a different format to the field after the CHARFORMAT switch has been
added.

--
Cheers
macropod
[Microsoft MVP - Word]


Doug Robbins - Word MVP said:
Hi Paul,

Just checked that and having the \* charformat at the end of the field construction did not cause any problem with the
functionality provided by the \h switch.

By default, the REF _Ref fields do not have a \* mergeformat switch.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
macropod said:
Hi Doug,

I think the macro should check for any \h switches in the fields concerned, as they'll throw a wobbly unless the \h switch comes
after the Charformat switch.

It's probably a good idea to delete any Mergeformat switches too, as they tell Word to format the field differently than the
Charformat switch and having both might lead to conflicts.

--
Cheers
macropod
[Microsoft MVP - Word]


Doug Robbins - Word MVP said:
Use a macro containing the following code to add the \* charformat switch to each of the cross reference fields and apply the
Italic formatting to the first letter of the field code which will cause the cross reference to be displayed in Italic font:

Dim afield As Field, i As Long
With ActiveDocument
For Each afield In .Fields
If afield.Type = wdFieldRef Then
With afield.Code
If InStr(.Text, "_Ref") > 0 Then
.Text = .Text & " \* charformat"
For i = 1 To .Characters.Count
If UCase(.Characters(i)) = "R" Then
.Characters(i).Font.Italic = True
Exit For
End If
Next i
End If
End With
End If
Next afield
.Range.Fields.Update
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
I have a document I want to be sure references for Appendix alpha-#, or
Exhibit #-#, or Table #-# or Figure #-# are italicized. And I have several
chapters to do this in. How to do? I do NOT want the actual caption on the
figure or table to pick up the italization but I want thses to retain their
figure or table title syles. Thanks
 
S

Suzanne S. Barnhill

Although Word does add the \* MERGEFORMAT switch if you apply the formatting
manually, it does not do so when you use F&R; see
http://sbarnhill.mvps.org/WordFAQs/FormatCrossReferences.htm.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org

macropod said:
Hi Doug,

I was testing this earlier with Word 2000, and found having the
CHARFORMATswitch after the \h switch resulted in and error message. Can't
reproduce it right now, though.

Also, if you try changing the format of a REF field from the keyboard,
Word (2000) automatically adds \* MERGEFORMAT to the field. It seems this
is just as likely to be an issue if one applies a different format to the
field after the CHARFORMAT switch has been added.

--
Cheers
macropod
[Microsoft MVP - Word]


Doug Robbins - Word MVP said:
Hi Paul,

Just checked that and having the \* charformat at the end of the field
construction did not cause any problem with the functionality provided by
the \h switch.

By default, the REF _Ref fields do not have a \* mergeformat switch.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
macropod said:
Hi Doug,

I think the macro should check for any \h switches in the fields
concerned, as they'll throw a wobbly unless the \h switch comes after
the Charformat switch.

It's probably a good idea to delete any Mergeformat switches too, as
they tell Word to format the field differently than the Charformat
switch and having both might lead to conflicts.

--
Cheers
macropod
[Microsoft MVP - Word]


Use a macro containing the following code to add the \* charformat
switch to each of the cross reference fields and apply the Italic
formatting to the first letter of the field code which will cause the
cross reference to be displayed in Italic font:

Dim afield As Field, i As Long
With ActiveDocument
For Each afield In .Fields
If afield.Type = wdFieldRef Then
With afield.Code
If InStr(.Text, "_Ref") > 0 Then
.Text = .Text & " \* charformat"
For i = 1 To .Characters.Count
If UCase(.Characters(i)) = "R" Then
.Characters(i).Font.Italic = True
Exit For
End If
Next i
End If
End With
End If
Next afield
.Range.Fields.Update
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
I have a document I want to be sure references for Appendix alpha-#,
or
Exhibit #-#, or Table #-# or Figure #-# are italicized. And I have
several
chapters to do this in. How to do? I do NOT want the actual caption
on the
figure or table to pick up the italization but I want thses to retain
their
figure or table title syles. Thanks
 
J

Janet A. Thompson

Doug,

I put this in my normal.dotx in 2007 but it shows 2 read lines in the
center"V" where I've put xxx's. How to fix? THANK YOU ALL.

' ChangetoItalic Macro
'
Dim afield As Field, i As Long
With ActiveDocument
For Each afield In .Fields
If afield.Type = wdFieldRef Then
With afield.Code
If InStr(.Text, "_Ref") > 0 Then
.Text = .Text & " \* charformat"
For i = 1 To .Characters.Count
xxx If UCase(.Characters(i)) = "R"
xxx .Characters(i).Font.Italic =
Exit For
End If
Next i
End If
End With
End If
Next afield
.Range.Fields.Update
End With V"
 
D

Doug Robbins - Word MVP

Looks like I forgot to paste in the code for dealing with the Exhibit and
Appendix.

Here it is:

Dim FindText As Variant, i As Long
FindText = Split("Exhibit/Appendix", "/")
For i = 0 To UBound(FindText)
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:=FindText(i), Forward:=True, _
MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=False) =
True
With Selection
.Font.Italic = True
.Collapse wdCollapseEnd
.MoveRight wdCharacter, 1
End With
Loop
End With
Next i

The reason that you are getting the errors on the other code is because in
the code that you posted, there is the word Then missing from the end of the
first line and the word True from the end of the second line. I am not sure
where they went to as they are included in the code at the bottom of this
message.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
Janet A. Thompson said:
Doug,

I put this in my normal.dotx in 2007 but it shows 2 read lines in the
center"V" where I've put xxx's. How to fix? THANK YOU ALL.

' ChangetoItalic Macro
'
Dim afield As Field, i As Long
With ActiveDocument
For Each afield In .Fields
If afield.Type = wdFieldRef Then
With afield.Code
If InStr(.Text, "_Ref") > 0 Then
.Text = .Text & " \* charformat"
For i = 1 To .Characters.Count
xxx If UCase(.Characters(i)) = "R"
xxx .Characters(i).Font.Italic =
Exit For
End If
Next i
End If
End With
End If
Next afield
.Range.Fields.Update
End With V"
 

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