Thread: Tim
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
tim tim is offline
external usenet poster
 
Posts: 105
Default Spurios Error

Yeah, ok, point taken!
Here it is, but it worked at one point:
Sub PopulateProposal()
'On Error GoTo errorHandler
Dim wdApp As Word.Application
Dim myDoc As Word.Document
Dim myRange As Word.Range

'open Word
Set wdApp = New Word.Application
With wdApp
.Visible = True
.WindowState = wdWindowStateMaximize
End With

'open Template
Worksheets("Deployment Input").Activate 'activate the
sheet with path details
Curfile = Range("H18") 'the path details of the
template
Set myDoc = wdApp.Documents.Open(Curfile)
Set myRange = myDoc.Words(1)

'mail merge
Curfile = ActiveWorkbook.Path + "\" + ActiveWorkbook.Name
With ActiveDocument.MailMerge
'load data range from spreadsheet
.MainDocumentType = wdCatalog
.OpenDataSource Name:=Curfile _
, ConfirmConversions:=False, ReadOnly:=False,
LinkToSource:=True, _
AddToRecentFiles:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"DSN=Excel Files;DBQ=" + Curfile
+ ";DriverId=22;MaxBufferSize=512;PageTimeout=5; " _
, SQLStatement:="SELECT * FROM
`MailMergeField`"
'do actual mail merge
'.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With