View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Ed[_31_] Ed[_31_] is offline
external usenet poster
 
Posts: 34
Default MailMerge Label printing from Excel

Nick,

I followed your suggestion but ran into a problem. Here is the code I
put into Excel VBA function, based on
a recorded Word macro:

Sub JOCLabels()
'
' JOCLabels Macro
' Macro recorded November 25, 2006 by Edward F. Sowell
'
Dim wdApp As Word.Application
Set wdApp = New Word.Application
With wdApp
ChangeFileOpenDirectory "D:\JOC\Membership\"
.Documents.Open fileName:="LabelLayout.doc",
ConfirmConversions:=False, _
ReadOnly:=False, AddToRecentFiles:=False,
PasswordDocument:="", _
PasswordTemplate:="", Revert:=False,
WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto
With ActiveDocument.MailMerge
' Fails at following stmt "Requested Object is not available"
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
ActiveDocument.SaveAs fileName:="testLabels.doc", FileFormat:=
_
wdFormatDocument, LockComments:=False, Password:="",
AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
ActiveWindow.Close
ActiveWindow.Close
End With

End Sub

As I indicate by the comment, it fails at the wdSendToNewDocument. My
guess is it has to do
with not having a needed Type or Object library in the References.
However, I've selected
Office 10 object library, Word 10 object library, and the MSM Merge
Type Library.

Any ideas?

Ed

"NickHK" wrote in message
...
Ed,
You can probably make a start by recording a macro in Word of the
MailMerge
actions.
Transfer the code to Excel and adjust reference to the Word
application
instead, same as you have done with Outlook.

NickHK