I am tring to do a mail merge between an Excel file and a Word template in vbscript within a DTS package. First, I get an error when I try and compile with the code:
doc.MailMerge.OpenDataSource Name:=strPath & strDataSource
I get a VB Script compilation error saying "Expected Statement."
Am I not declaring the data source correctly? Is my syntax wrong? Any suggestions would be great appreciated.
Here is the code I have so far:
Function Main()
Dim strPath
Dim strDataSource
Dim strTemplate
Dim doc
Dim wrdApp
Set wrdApp = CreateObject("Word.Application"
strPath = "C:\MailingLabel\"
strTemplate = "MailingLabelTemplate.dot"
strDataSource = "Address.xls"
' Start Word using mailmerge template
Set doc = wrdApp.Documents.Add(strPath & strTemplate)
'CreateDataDoc strDataSource
' Do the mail merge to a new document.
doc.MailMerge.OpenDataSource Name:=strPath & strDataSource
doc.MailMerge.Destination = wdSendToNewDocument
doc.MailMerge.SuppressBlankLines = True
doc.DataSource.FirstRecord = wdDefaultFirstRecord
doc.DataSource.LastRecord = wdDefaultLastRecord
If docMailMerge.State = wdMainAndDataSource Then
doc.MailMerge.Execute
End if
' Display the mail merge document
wrdApp.Visible = True
Set doc = Nothing
Set wrdApp = Nothing
Main = DTSTaskExecResult_Success
End Function
doc.MailMerge.OpenDataSource Name:=strPath & strDataSource
I get a VB Script compilation error saying "Expected Statement."
Am I not declaring the data source correctly? Is my syntax wrong? Any suggestions would be great appreciated.
Here is the code I have so far:
Function Main()
Dim strPath
Dim strDataSource
Dim strTemplate
Dim doc
Dim wrdApp
Set wrdApp = CreateObject("Word.Application"
strPath = "C:\MailingLabel\"
strTemplate = "MailingLabelTemplate.dot"
strDataSource = "Address.xls"
' Start Word using mailmerge template
Set doc = wrdApp.Documents.Add(strPath & strTemplate)
'CreateDataDoc strDataSource
' Do the mail merge to a new document.
doc.MailMerge.OpenDataSource Name:=strPath & strDataSource
doc.MailMerge.Destination = wdSendToNewDocument
doc.MailMerge.SuppressBlankLines = True
doc.DataSource.FirstRecord = wdDefaultFirstRecord
doc.DataSource.LastRecord = wdDefaultLastRecord
If docMailMerge.State = wdMainAndDataSource Then
doc.MailMerge.Execute
End if
' Display the mail merge document
wrdApp.Visible = True
Set doc = Nothing
Set wrdApp = Nothing
Main = DTSTaskExecResult_Success
End Function