S
stevew
I am trying to create a mailmerge in excel with the click of a button. When
the button is clicked it opens word sucessfully.
Sub OpenWord()
Dim wdApp As Object
Dim wdDoc As Object
Set wdApp = CreateObject("Word.application")
Set wdDoc = wdApp.Documents.Open _
(Filename:="C:\Documents and Settings\steve\My
Documents\MyTestDoc.doc")
wdDoc.Close savechanges:=False
Set wdDoc = Nothing
wdApp.Quit
Set wdApp = Nothing
End Sub
The code I have placed in Word gives me an error (Ambiguous selection) at
the second line .Destination=wdsendToPrinter.
Private Sub Document_Open()
With ActiveDocument.mailmerge
.Destination = wdSendToPrinter
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
End Sub
I'm making the assumption (new to VBA in excel and word) that the document
is not
active but the spreadsheet is and therefore will not print. Not sure how to
solve this.
If anyone can give me any assistance it would be very much appreciated.
Steve Walker
the button is clicked it opens word sucessfully.
Sub OpenWord()
Dim wdApp As Object
Dim wdDoc As Object
Set wdApp = CreateObject("Word.application")
Set wdDoc = wdApp.Documents.Open _
(Filename:="C:\Documents and Settings\steve\My
Documents\MyTestDoc.doc")
wdDoc.Close savechanges:=False
Set wdDoc = Nothing
wdApp.Quit
Set wdApp = Nothing
End Sub
The code I have placed in Word gives me an error (Ambiguous selection) at
the second line .Destination=wdsendToPrinter.
Private Sub Document_Open()
With ActiveDocument.mailmerge
.Destination = wdSendToPrinter
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
End Sub
I'm making the assumption (new to VBA in excel and word) that the document
is not
active but the spreadsheet is and therefore will not print. Not sure how to
solve this.
If anyone can give me any assistance it would be very much appreciated.
Steve Walker