S
Steven Lee
Hi,
We recently migrated from Word 2000 to Word 2003. We have a ton of VBA code
that we use in house and are finding some issues between the two versions.
We have code that looks through a document and finds italic, bold, etc. and
wraps the text with codes similar to HTML (we're coding for InDesign and
Ventura)
When running a coding macro to tag italic formatting on a document that has
tables I found that Selection.Find.Found returns true, and the macro
continues to run, even though we've found and tagged all the italic.
'These are the tags we're adding for italic
startcode$ = "<I>"
endocde$ = "<I*>"
'First I set up the search:
With Selection.Find
.ClearFormatting
.Font.Italic = True
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
'Then I execute the search
Selection.Find.execute
While Selection.Find.Found
ActiveDocument.UndoClear
Selection.MoveLeft wdCharacter, 1 'start of the italic
string
Selection.TypeText startcode$ 'add the startcode
If Len(startcode$) <> 0 Then
'go back over the startcode and set it to default
para font
Selection.MoveLeft wdCharacter, Len(startcode$),
wdExtend
Selection.Style = "Default Paragraph Font"
Selection.MoveRight wdCharacter, 1
'we're back at the start of the italic string
Selection.Find.Execute
'puts the cursor at the end of the string
Selection.MoveRight wdCharacter, 1
'we're at the end of the italic string
Selection.TypeText Text:=endcode$ 'add the
end code
If Len(endcode$) <> 0 Then
'swipe the end code and set it to default para
Selection.MoveLeft wdCharacter, Len(endcode$),
wdExtend
Selection.Style = "Default Paragraph Font"
Selection.MoveRight wdCharacter, 1
'we're at the end of the endcode, ready to look for
more italic
End If
Selection.Find.Execute
'when we hit the last of the italic Selection.Find in
Word 2000, selection.find.found = false and we exit the loop, but in 2003
it's true, but when the search executes again the cursor stays put and keeps
on typing startcode$ and endcode$ over and over as infinitum.
Wend
I can't turn off the italic (what if it's bold and italic, then I need to
come back and do bold.)
If I run this on a document with no tables it works fine.
Any help would be most appreciated!!
Thanks in advance,
Steven Lee
Vaporloop - Technology Solutions for Small Businesses
We recently migrated from Word 2000 to Word 2003. We have a ton of VBA code
that we use in house and are finding some issues between the two versions.
We have code that looks through a document and finds italic, bold, etc. and
wraps the text with codes similar to HTML (we're coding for InDesign and
Ventura)
When running a coding macro to tag italic formatting on a document that has
tables I found that Selection.Find.Found returns true, and the macro
continues to run, even though we've found and tagged all the italic.
'These are the tags we're adding for italic
startcode$ = "<I>"
endocde$ = "<I*>"
'First I set up the search:
With Selection.Find
.ClearFormatting
.Font.Italic = True
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
'Then I execute the search
Selection.Find.execute
While Selection.Find.Found
ActiveDocument.UndoClear
Selection.MoveLeft wdCharacter, 1 'start of the italic
string
Selection.TypeText startcode$ 'add the startcode
If Len(startcode$) <> 0 Then
'go back over the startcode and set it to default
para font
Selection.MoveLeft wdCharacter, Len(startcode$),
wdExtend
Selection.Style = "Default Paragraph Font"
Selection.MoveRight wdCharacter, 1
'we're back at the start of the italic string
Selection.Find.Execute
'puts the cursor at the end of the string
Selection.MoveRight wdCharacter, 1
'we're at the end of the italic string
Selection.TypeText Text:=endcode$ 'add the
end code
If Len(endcode$) <> 0 Then
'swipe the end code and set it to default para
Selection.MoveLeft wdCharacter, Len(endcode$),
wdExtend
Selection.Style = "Default Paragraph Font"
Selection.MoveRight wdCharacter, 1
'we're at the end of the endcode, ready to look for
more italic
End If
Selection.Find.Execute
'when we hit the last of the italic Selection.Find in
Word 2000, selection.find.found = false and we exit the loop, but in 2003
it's true, but when the search executes again the cursor stays put and keeps
on typing startcode$ and endcode$ over and over as infinitum.
Wend
I can't turn off the italic (what if it's bold and italic, then I need to
come back and do bold.)
If I run this on a document with no tables it works fine.
Any help would be most appreciated!!
Thanks in advance,
Steven Lee
Vaporloop - Technology Solutions for Small Businesses