D
Debra Farnham
Hi again everyone
Win 2K
Word 2K
I have the following not so elegant code to italicize text, between hyphens,
in a custom document property named Offence.
Dim SearchString, SearchChar, MyFirstHyphen, MySecondHyphen, Phrase
SearchChar = "-" ' Search for "-".
SearchString = ActiveDocument.CustomDocumentProperties("Offence") ' String
to search in.
'find first hyphen
MyFirstHyphen = InStr(4, SearchString, SearchChar, 1) + 1
'find second hyphen
MySecondHyphen = InStr(MyFirstHyphen, SearchString, SearchChar, 1) -
MyFirstHyphen - 1
Phrase = Mid(SearchString, MyFirstHyphen, MySecondHyphen)
'Italicize Text
Selection.Find.Replacement.Font.Italic = True
With Selection.Find
.Text = Phrase
.Replacement.Text = Phrase
.Forward = True
.Wrap = wdFindContinue
.Format = True
End With
Selection.Find.Execute
With Selection
If .Find.Forward = True Then
.Collapse direction:=wdCollapseStart
Else
.Collapse direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse direction:=wdCollapseEnd
Else
.Collapse direction:=wdCollapseStart
End If
.Find.Execute
End With
Selection.GoTo what:=wdGoToBookmark, name:="Start"
The problem is, I need to loop it through the custom property so if there
are further pairs of hyphens in the custom property, that it italicizes them
as well.
Any suggestions on cleaning up the italicization would be greatly
appreciated as well.
I don't know why, but I cannot wrap my head around looping.
TIA
Debra
Win 2K
Word 2K
I have the following not so elegant code to italicize text, between hyphens,
in a custom document property named Offence.
Dim SearchString, SearchChar, MyFirstHyphen, MySecondHyphen, Phrase
SearchChar = "-" ' Search for "-".
SearchString = ActiveDocument.CustomDocumentProperties("Offence") ' String
to search in.
'find first hyphen
MyFirstHyphen = InStr(4, SearchString, SearchChar, 1) + 1
'find second hyphen
MySecondHyphen = InStr(MyFirstHyphen, SearchString, SearchChar, 1) -
MyFirstHyphen - 1
Phrase = Mid(SearchString, MyFirstHyphen, MySecondHyphen)
'Italicize Text
Selection.Find.Replacement.Font.Italic = True
With Selection.Find
.Text = Phrase
.Replacement.Text = Phrase
.Forward = True
.Wrap = wdFindContinue
.Format = True
End With
Selection.Find.Execute
With Selection
If .Find.Forward = True Then
.Collapse direction:=wdCollapseStart
Else
.Collapse direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse direction:=wdCollapseEnd
Else
.Collapse direction:=wdCollapseStart
End If
.Find.Execute
End With
Selection.GoTo what:=wdGoToBookmark, name:="Start"
The problem is, I need to loop it through the custom property so if there
are further pairs of hyphens in the custom property, that it italicizes them
as well.
Any suggestions on cleaning up the italicization would be greatly
appreciated as well.
I don't know why, but I cannot wrap my head around looping.
TIA
Debra