sturner970
06-23-2006, 10:04 AM
I created a mailmerge macro for producing labels, using the macro wizard and a Quickbooks client database for the source data. The recording and label results went smoothly, utilizing the matching fields, sort, and selection capabilities. I then stopped recording, exited WORD entirely, re-entered WORD. The macro (placed into normal.dot) was executed from the Run macro area, and produced an error 509 (couldn't locate the command) on the last macro line: mailmerge.propagatelabels.
Seemed curious that the results during the recording worked fine, but the code generated failed. Any clues? Is that particular function non-recordable? Is there a work-around?
Here is the code:
Sub Macro8()
'
' Macro8 Macro
' Macro recorded 6/22/2006 by xxxxxxxxx
'
ActiveDocument.MailMerge.MainDocumentType = wdMailingLabels
ActiveDocument.MailMerge.OpenDataSource Name:= _
"C:\WINWORD\SBCI\MacroStuff\custdata.doc", ConfirmConversions:=False, _
ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
Connection:="", SQLStatement:="", SQLStatement1:="", SubType:= _
wdMergeSubTypeOther
ActiveDocument.Fields.Add Range:=Selection.Range, Type:= _
wdFieldAddressBlock, Text:= _
"\f ""<<_FIRST0_>><< _LAST0_>><< _SUFFIX0_>>" & Chr(13) & "<<_STREET1_" & _
Chr(13) & ">><<_STREET2_" & Chr(13) & ">><<_CITY_>><<, _STATE_>>" & _
"<< _POSTAL_>>"" \l 1033 \c 0 \e ""United States"" \d"
Application.Dialogs(wdDialogMailMergeRecipients).Show 1000
WordBasic.MailMergePropagateLabel
End Sub
Edited 24-Jun-06 by geekgirlau. Reason: insert vba tags
Seemed curious that the results during the recording worked fine, but the code generated failed. Any clues? Is that particular function non-recordable? Is there a work-around?
Here is the code:
Sub Macro8()
'
' Macro8 Macro
' Macro recorded 6/22/2006 by xxxxxxxxx
'
ActiveDocument.MailMerge.MainDocumentType = wdMailingLabels
ActiveDocument.MailMerge.OpenDataSource Name:= _
"C:\WINWORD\SBCI\MacroStuff\custdata.doc", ConfirmConversions:=False, _
ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
Connection:="", SQLStatement:="", SQLStatement1:="", SubType:= _
wdMergeSubTypeOther
ActiveDocument.Fields.Add Range:=Selection.Range, Type:= _
wdFieldAddressBlock, Text:= _
"\f ""<<_FIRST0_>><< _LAST0_>><< _SUFFIX0_>>" & Chr(13) & "<<_STREET1_" & _
Chr(13) & ">><<_STREET2_" & Chr(13) & ">><<_CITY_>><<, _STATE_>>" & _
"<< _POSTAL_>>"" \l 1033 \c 0 \e ""United States"" \d"
Application.Dialogs(wdDialogMailMergeRecipients).Show 1000
WordBasic.MailMergePropagateLabel
End Sub
Edited 24-Jun-06 by geekgirlau. Reason: insert vba tags