Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace not working in VBA - Word 2000 1

Status
Not open for further replies.

webcats

Programmer
Apr 24, 2002
60
US
Hi all,

I'm trying to build a macro in Word 2k that will replace certain text. I did a record macro and it built the macro and replaced the text, but when I run the macro, it doesn't do anything. The text I want to replace is in a Text Box... do you think that's the problem? Any help would be appreciated. Thanks. Here is the macro:

Sub ReplaceNum()
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "+"
.Replacement.Text = "1234567"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
Collate:=False, Background:=False, PrintToFile:=False, PrintZoomColumn:=0 _
, PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
End Sub

"One Database to rule them all, One Database to find them,
One Database to bring them all and in the darkness bind them."
 
It's a Text box... Like if you go to Insert -> Text Box.

"One Database to rule them all, One Database to find them,
One Database to bring them all and in the darkness bind them."
 
Hi,

Try this
Code:
    For Each sh In ActiveDocument.Shapes
        sh.Select
        With Selection.Find
            .Text = "+"
            .Replacement.Text = "1234567"
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
    Next
:)

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Skip,

Excellant! That works like a charm. Thanks!

"One Database to rule them all, One Database to find them,
One Database to bring them all and in the darkness bind them."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top