Running find and replace in word from access

J

Jon Petitta

I have been developing on one machine and of course when I
move to another one I get a problem. They are both Win
2000 adv server, and Office XP. The problem is with the
version of Word, the code will run when you use verion
10.4219.4219, but doesn't on 10.5522.4219. It gives me an
invalid procedure call, anyone know what is going on.
here's the code.

Dim oApp as Word.Application
Set oApp = New word.Application
oApp.Visible = True
oApp.Documents.Open ("C:\dir\file.doc")

With oApp.Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "%ClientName"
.Replacement.Text = strClientName
.Execute Replace:=wdReplaceAll
.ClearFormatting
.Replacement.ClearFormatting
.Text = "%SiteSTreet"
.Replacement.Text = strSStreet
.Execute Replace:=wdReplaceAll
.ClearFormatting
.Replacement.ClearFormatting
.Text = "%SiteCity"
.Replacement.Text = strSCity
.Execute Replace:=wdReplaceAll
.ClearFormatting
.Replacement.ClearFormatting
.Text = "%SiteState"
.Replacement.Text = strSState
.Execute Replace:=wdReplaceAll
.ClearFormatting
.Replacement.ClearFormatting
.Text = "%SiteZip"
.Replacement.Text = strSZip
.Execute Replace:=wdReplaceAll
End With

oApp.ActiveWindow.ActivePane.View = wdPrintView
oApp.ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
oApp.ActiveWindow.ActivePane.View.NextHeaderFooter

With oApp.Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "%ClientName"
.Replacement.Text = strClientName
.Execute Replace:=wdReplaceAll
End With


oApp.ActiveDocument.SaveAs ("C:\dir\otherfile.doc")
oApp.Application.Quit

If I take out the find and replace code and just do the
open and save as it works ok. I even took out the find
code and just did oApp.Selection.Find.Text = "" and gave
the same error.

Any help would be great.
Jon
 
G

Geoff

Your code also works fine in Access/Word 2K.

A few thoughts:

Will the code compile on both machines?

When you get the error message "invalid
procedure call", does the code run at all?

If you put a breakpoint on the first code line,
does the program get that far?

If you step through the code, where does it stop?

Geoff
 

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