Use Find and Replace to change style

M

mcambrose

Can I use find/replace to change any text following a return character that
is italic.

For example I have the following:
[return character]
Italic text 1. Other text which is not italic
Some other text
[return character]
Italic text 2.
Some other text

i want to find the Italic text that starts a new paragraph. I want to change
the text from italic to bold formatting. The text only includes letters and
spaces.

Thanks
 
G

Greg Maxey

Sub ScratchMacro()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Font.Italic = True
While .Execute
On Error GoTo Err_Handler
If oRng.Characters.First.Previous = Chr(13) Then
oRng.Font.Italic = False
oRng.Font.Bold = True
oRng.Collapse wdCollapseEnd
End If
Err_ReEntry:
Wend
End With
Exit Sub
Err_Handler:
Resume Err_ReEntry
End Sub

Can I use find/replace to change any text following a return
character that is italic.

For example I have the following:
[return character]
Italic text 1. Other text which is not italic
Some other text
[return character]
Italic text 2.
Some other text

i want to find the Italic text that starts a new paragraph. I want to
change the text from italic to bold formatting. The text only
includes letters and spaces.

Thanks
 
M

mcambrose

Thank you this works like a charm. I will look it over to see if I can
understand exactly what you did, so I can adapt for things in the future. I
program for excel, but I haven;t done much for Word.

Greg Maxey said:
Sub ScratchMacro()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Font.Italic = True
While .Execute
On Error GoTo Err_Handler
If oRng.Characters.First.Previous = Chr(13) Then
oRng.Font.Italic = False
oRng.Font.Bold = True
oRng.Collapse wdCollapseEnd
End If
Err_ReEntry:
Wend
End With
Exit Sub
Err_Handler:
Resume Err_ReEntry
End Sub

Can I use find/replace to change any text following a return
character that is italic.

For example I have the following:
[return character]
Italic text 1. Other text which is not italic
Some other text
[return character]
Italic text 2.
Some other text

i want to find the Italic text that starts a new paragraph. I want to
change the text from italic to bold formatting. The text only
includes letters and spaces.

Thanks
 
G

Greg Maxey

The issue was your criteria to change italic text to bold "only if" it
followed a return character. So first you find the italic text, then look
to see if it is preceeded by a Chr(13) (or the return character) and if so
change it to bold. This process will throw an error if the first line of
text is italic (there is no previous character). That is why I included an
error handler.


Thank you this works like a charm. I will look it over to see if I can
understand exactly what you did, so I can adapt for things in the
future. I program for excel, but I haven;t done much for Word.

Greg Maxey said:
Sub ScratchMacro()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Font.Italic = True
While .Execute
On Error GoTo Err_Handler
If oRng.Characters.First.Previous = Chr(13) Then
oRng.Font.Italic = False
oRng.Font.Bold = True
oRng.Collapse wdCollapseEnd
End If
Err_ReEntry:
Wend
End With
Exit Sub
Err_Handler:
Resume Err_ReEntry
End Sub

Can I use find/replace to change any text following a return
character that is italic.

For example I have the following:
[return character]
Italic text 1. Other text which is not italic
Some other text
[return character]
Italic text 2.
Some other text

i want to find the Italic text that starts a new paragraph. I want
to change the text from italic to bold formatting. The text only
includes letters and spaces.

Thanks
 

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