PDA

View Full Version : Solved: WORD 2003 can't locate its mailmerge code



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

geekgirlau
06-23-2006, 09:18 PM
Welcome to the board!

Sorry, I don't have an answer for you - just a quick note to let you know I've edited your post to include VBA tags. If you are posting code, select the code text and click on the VBA button - it makes it a lot easier to read.

sturner970
06-23-2006, 09:34 PM
Thx, geekgirlau........appreciate the tip......looks like a fun place to get good info.

Sturner

sturner970
06-26-2006, 08:57 PM
Answer The problem appears to be that the code is NOT creating a table for the document, so the propagateLabel cannot work due to lack of table. HOWEVER, the macro looks very specific, so I'm not sure why you need it as a macro - once the document has been created, simply save it as a template (file, saveas, files of type document template) and every time you need a blank document use the file new menu to access this template.

Anonymous

fumei
06-26-2006, 09:15 PM
Dah-dah! And THAT is what templates are for.

ansari
08-26-2008, 09:16 AM
you must make your main document type as MailingLabel
add this line after you load your document.

.ActiveDocument.MailMerge.MainDocumentType = Word.WdMailMergeMainDocType.wdMailingLabels