Hi aw23,
The posted code has not come from the Macro Recorder, not directly anyway.
Font.Italic is Boolean; it is either True or False. When you assign it to your
String variable you get the string representation of True ("-1") or False ("0") depending on the font of the Selection BEFORE the Find.
Having got a string, you are searching for it as
Text and either finding it or not depending on the content of your document, but you are not looking for italicised text at all.
I just recorded looking for italics and got this ..
Code:
[blue]Sub Macro1()
[green]'
' Macro1 Macro
' Macro recorded 17/05/2004 by Tony
'[/green]
Selection.Find.ClearFormatting
Selection.Find.Font.Italic = True
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
End Sub[/blue]
There are a couple of significant differences. The Font.Italic Property of the
Find Object is set to True, and the Text being searched for is set to an empty string, with these two lines of code ..
[blue][tt] Selection[highlight].Find[/highlight].Font.Italic = [highlight]True[/highlight][/tt][/blue]
.. and ..
[blue][tt] .Text = ""[/tt][/blue]
One further point about your code is the [purple][tt]MessageBox.Show[/tt][/purple] statement. The correct VBA statement is just [blue][tt]MsgBox[/tt][/blue]
Enjoy,
Tony
--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.