executing a word vba code from access

S

snaggy^^

I need to create a vba macro in access 2007 that opens a word 2007 document,
fills in the correct data from an access record (just one, not recursive) and
print it out.

I thought to open a document with symbols where I want to fill in data (like
<<1>> <<2>> etc), and the use find and replace to do it.
here's what I wrote:

Set objWord = CreateObject("Word.Application")
objWord.Documents.Open ("c:\Liquid\template.docx")
objWord.Visible = True
With objWord
..Selection.Find.ClearFormatting
.Selection.Find.Replacement.ClearFormatting
With .Selection.Find
.Text = "<<1>>"
.Replacement.Text = "something"
.MatchCase = True
End With
.Selection.Find.Execute Replace:=wdReplaceAll
End With

it does open the file and select the first occurrence to replace, but then
nothing happens!
Why?

bye and thank you all
 
S

snaggy^^

The point is that it doesn't work! It doesn't replace the instances of <<1>>
whene executed from access, while when it's executed from word it works.

bye
 
S

snaggy^^

Another thing..

How can I tell him to work on a specific file? Look at this:

Set objDoc as CreateObject("Word.Application.Documents.Open("path")")

shouldn't it work? whith nested quotes written like Chr(34)?

Or should I use ActiveDocument (i tried of course, but it gives me a
debugging error)

bye
 
D

Doug Robbins - Word MVP

Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open("c:\Liquid\template.docx")


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
S

snaggy^^

I read your bookmark tutorial and loved it! It solves my problem in a great
way! It works perfectly

bye and thanks
 

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