View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
stevew stevew is offline
external usenet poster
 
Posts: 5
Default Mailmerge from a button in excel

Trying not to. I want to mail letters for the data in excel but use excel as
the main application.

Steve

"Kassie" wrote in message
...
Shouldn't you do this from Word?

"stevew" wrote:

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) 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