make word vb work from msaccess

S

slickdock

I have this simple macro in word, and I'd like to execute it from an msAccess
module:

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "a"
.Replacement.Text = "b"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

I know enough to preface the above code with:
Dim wd As Object
Dim wdActiveDoc As Object
Dim wdField As Object
Set wd = CreateObject("Word.Application")

Then I know enough to add the following wd. prefix to these lines:
wd.Selection.Find.ClearFormatting
wd.Selection.Find.Replacement.ClearFormatting
With wd.Selection.Find

But after the END WITH, it's bombing out on this line:
wd.Selection.Find.Execute Replace:=wdReplaceAll

Any help would be greatly appreciated.
 
T

Tony Jollans

wdReplaceAll is a Word constant and you are using late binding - use the
constant instead, or qualify it (wd.wdreplaceall).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top