In 2002, the following macro does what it is intended to do with the lines
of code commented out as indicated:
In 2003, only the first Find Replace is executed on the active document as
the focus moves to another open document. In fact, clicking on the scroll
bar in the "active document" activates the other document which has assumed
the focus.
If the lines that are commented out are uncommented, so that the active
document is "activated" before each Find Replace, the macro does what it is
intended to do in Word 2003.
Alternatively, if all of the With Selection.Find are replaced by With
ActiveDocument.Content.Find, the full code is executed on the active
document:
' Dim mydoc As Document
' Set mydoc = ActiveDocument
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Execute FindText:="(OH )([0-9)]{5})^13(SSN:
[0-9]{3}-[0-9]{2}-[0-9]{4}^13)", MatchWildcards:=True,
ReplaceWith:="\1\2^p^p", Wrap:=wdFindContinue, Forward:=True,
Replace:=wdReplaceAll
End With
' mydoc.Activate
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Execute FindText:="[0-9]{3}-[0-9]{3}-[0-9]{4}^13",
MatchWildcards:=True, ReplaceWith:="^p", Wrap:=wdFindContinue,
Forward:=True, Replace:=wdReplaceAll
End With
' mydoc.Activate
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Execute FindText:="^p^p", MatchWildcards:=False, ReplaceWith:="##",
Wrap:=wdFindContinue, Forward:=True, Replace:=wdReplaceAll
End With
' mydoc.Activate
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Execute FindText:="(OH )([0-9)]{5})^13", MatchWildcards:=True,
ReplaceWith:="\1\2##", Wrap:=wdFindContinue, Forward:=True,
Replace:=wdReplaceAll
End With
' mydoc.Activate
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Execute FindText:="^p", MatchWildcards:=False, ReplaceWith:="^t",
Wrap:=wdFindContinue, Forward:=True, Replace:=wdReplaceAll
End With
' mydoc.Activate
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Execute FindText:="##", MatchWildcards:=False, ReplaceWith:="^p",
Wrap:=wdFindContinue, Forward:=True, Replace:=wdReplaceAll
End With
' mydoc.Activate
' mydoc.Range.ConvertToTable Separator:=wdSeparateByTabs, NumColumns:=5
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP