Group:  Microsoft Access » microsoft.public.access.formscoding
Thread: Find/replace in a Word document programmatically?

Geek News

Find/replace in a Word document programmatically?
robeito 12/1/2008 4:41:02 PM
Hi everybody
I have an Access project with the following code in a form:

Public Sub saleAword()
Dim oWord As Object
Dim oWdoc As Object

On Error Resume Next
Set oWord = GetObject(, "Word.Application")
If Err.Number = 429 Then Set oWord = CreateObject("Word.Application")
On Error Goto 0

Set oWdoc = oWord.Documents.Add(CurrentProject.Path &
"\miDocWordOriginal.doc")

oWdoc.content.Find.Execute "#año#", False, , , , , , , , Nz(Me.Año),
wdReplaceAll

oWdoc.content.Find.Execute "#objetivo#", False, , , , , , , ,
Nz(Me.Objetivo), wdReplaceAll
....
....

I'm trying to replace every occurrence of the word "#año#" and
"#objetivo#" by the corresponding current values in the form.

The code works fine for "#año#" , but fails replacing "#objetivo#" because
that field has over 500 characters long

Is there another way to do this?

Thanks in advance!!

By the way, oWdoc.content.Find.Execute is not working in headers :(

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net