Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Visual Basic (Microsoft) Versions 5/6 FAQ

MS Word Automation

How do I pass data to MS word document? by tty0
Posted: 20 Feb 03 (Edited 15 Oct 03)

As this has been asked a couple of times over the past month I thought I would do a quick writeup and some links.

There are many uses for Word using VB6, one of them is as below:
I had a client that wished to build letters in MSWord which they could pick and choose at will and populate with customer names and addresses etc from a list. So each letter that they designed in word has a set of bookmarks, one for each of the customer details. The software then went off and according to a criteria built a list and dumped the letters to a printer with the correct details on.

To make this easier to see I have put only the code for the transfer from a form with 5 textboxes on it labelled


the code is behind a command button which takes the strings from the text boxes and puts them into the appropriate bookmarks.
Private Sub cmdButtom_Click()

Dim WordObj As Word.Application
Set WordObj = CreateObject("Word.Application")
Dim objWord As Word.Document
Set objWord = WordObj.Documents.Open(FileName:=App.Path & "\INVOICE.doc")
WordObj.visible = true
With objWord.Bookmarks
    .Item("NAME").Range.Text = txtName
    .Item("ADDRESS").Range.Text = txtAddress
    .Item("CODE").Range.Text = txtCode
    .Item("PHONE").Range.Text = txtPhone
    .Item("FAX").Range.Text = txtFax
End With
Set objWord = Nothing

End Sub

The word object model is extensive as are most and a full run down can be found on the MS site here:


If you are wanting a demo of the code zipped up with the document, email me on chris@techsupportuk.com or ICQ 82621399 and i'll send it on.

Have fun!

Back to Visual Basic (Microsoft) Versions 5/6 FAQ Index
Back to Visual Basic (Microsoft) Versions 5/6 Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close