Problems with "Merge with Word" Code



Hi all
I'm trying to use the following code, to retrieve data from "name" time
and place text boxs on a form ,into respective bookmarks on a word
template file (
When I run the code, word application opens, a printout comes out but
without the data to be reterieved.
Please help
Thanks in advance

Private Sub Command6_Click()
'Declare variables for storing string(text)
Dim name, time, place As String

name = [name]
time = [time]
place = [place]

'Declare an instance of Microsoft Word.
Dim Wrd As New Word.Application
Set Wrd = CreateObject("Word.Application")

'Specify the path and name to the word document
Dim MergeDoc As String
MergeDoc = Application.CurrentProject.Path
MergeDoc = MergeDoc + "\"

'Open the document template and make it visible
Wrd.Documents.Add MergeDoc
Wrd.Visible = True

'Replace each bookmark with current data
With Wrd.ActiveDocument.Bookmarks
.Item("name").Range.Text = name
.Item("time").Range.Text = time
.Item("place").Range.Text = Range

End With

'Document is ready to print

'Close the document without saving
Wrd.ActiveDocument.Close wdDoNotSaveChanges
End Sub



Albert D. Kallal

Why don't you dump those books marks.

Try downloading and running my sample. My same works for all forms, and you
do NOT have to write code, and hard code a bunch of bookmarks each time.
Further, to build the word template, you just insert regular and nice and
easy to use word merge fields.

Give my example a try...and never have to hard code a bunch of hard to use
bookmarks again...

You can find the easy word merge here:

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