Article ID: 138289
Article Last Modified on 10/11/2006
(Note that the Continue button is unavailable.)
-or-
Sub Create_Mailing_Labels()
Dim Word As Object
Set Word = CreateObject("word.basic") 'creates the Word object
With Word
.AppShow ' Makes Word Visible
'Sends keystrokes to the Open Worksheet dialog
SendKeys "{TAB}{TAB}{TAB}{ENTER}"
'opens a the Microsoft Excel file
'NOTE: This line needs to be changed to point to the data file
'(i.e. "c:\data.xls")
.FileOpen Name:="c:\<path>\<filename>"
'NOTE: This line needs to be changed to point to a new name for
'the file (i.e. "c:\data.doc")
'saves the file as a Microsoft Word document
.FileSaveAs Name:="c:\<path>\<filename>"
.FileClose 'closes the file
.FileNewDefault ' Opens up a new blank document
'makes the active window a main document
.MailMergeMainDocumentType 1
' opens up the data source
'NOTE: This line needs to be changed to point to the new file
'(i.e. "c:\data.doc")
.MailMergeOpenDataSource Name:="c:\<path>\<filename>", LinkToSource:=0
'THESE FIELDS WILL BE SPECIFIC TO THE DATA BEING USED
'Sets up the fields to be used for the mail merge
.ToolsCreateLabels LabelAutoText:="ToolsCreateLabels3",_
LabelText:="<<CONTACT>>" + Chr$(13) + "<<ADDRESS>>" + Chr$(13) + _
"<<CITY>>, <<REGION>> <<ZIP_CODE>> <<COUNTRY>>"
.MailMergeToDoc 'Merges data records with the main document
' saves the active document
'NOTE: This line needs to be changed to point a new file name
'(i.e. "c:\result.doc")
.FileSaveAs Name:="c:\<path>\<filename>"
End With
Set word = Nothing 'clears the object variable
End Sub
Additional query words: XL7
Keywords: kbinterop kbprogramming KB138289