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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Macro - Search & Replace 1

Status
Not open for further replies.

jthomas666

Technical User
Sep 5, 2001
74
US
Word 07

I'm working on a project to automate document generation. To do this, I need to be able to input some variables, and then replace certain strings in the document with those variables.

I've managed to cobble together the following code, but it isn't working.

------------------
Main = InputBox("What is the Release Line for this bulletin? (CS08 V2, CS08 V3, V5.57, etc.")
With Selection.Find
.Text = "[Release Line]"
.Replacement.Text = Main
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection.Find
.Text = "[Release Name]"
.Replacement.Text = SBName
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
------------------------------------

What am I doing wrong?
 
I can't test using Word 07 but testing in 2003, it would appear you need to execute the find. Here's some example code
Code:
With Selection.Find
        .Text = "[Release Line]"
        .Replacement.Text = Main
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        [red].Execute Replace:=wdReplaceAll[/red]
    End With
You also don't seem to set the value of SBName in your posted code.

Also, as this isn't a VB5&6 question, you might be better off posting any future questions related to Office VBA in forum707

Hope this helps

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top