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
txtName
txtAddress
txtCode
txtPhone
txtFax
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:
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.