taffey
Programmer
- Apr 16, 2007
- 2
My mail merge is running ver slow when using opendatasource.
Sub Mergeit(strFileName)
'Merge the data from the Excel Spreadsheet to the Active Word Document
Dim objWord
Dim objDoc
Dim datasource As String
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
MsgBox strFileName
'Set objDoc = WordDocuments.Open(strFileName1)
' now open the contract document based on the Selling Resort and the resort
Set objDoc = objWord.Documents.Open(strFileName)
' now get the mailmerge object
'Set wrdMerge = objDoc.MailMerge
With objWord.ActiveDocument.MailMerge
.opendatasource Name:="C:\me\data_Contracts_spi", _
Connection:="Entire Spreadsheet", SQLStatement:="", SQLStatement1:=""
.Destination = wdSendToNewDocument
.MailAsAttachment = True
.SuppressBlankLines = True
'set the record count of the datasource for one record
With .datasource
.FirstRecord = 1
.LastRecord = 1
End With
.Execute Pause:=True
End With
end sub
Sub Mergeit(strFileName)
'Merge the data from the Excel Spreadsheet to the Active Word Document
Dim objWord
Dim objDoc
Dim datasource As String
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
MsgBox strFileName
'Set objDoc = WordDocuments.Open(strFileName1)
' now open the contract document based on the Selling Resort and the resort
Set objDoc = objWord.Documents.Open(strFileName)
' now get the mailmerge object
'Set wrdMerge = objDoc.MailMerge
With objWord.ActiveDocument.MailMerge
.opendatasource Name:="C:\me\data_Contracts_spi", _
Connection:="Entire Spreadsheet", SQLStatement:="", SQLStatement1:=""
.Destination = wdSendToNewDocument
.MailAsAttachment = True
.SuppressBlankLines = True
'set the record count of the datasource for one record
With .datasource
.FirstRecord = 1
.LastRecord = 1
End With
.Execute Pause:=True
End With
end sub