MailMerge Macro Help

D

David

Greetings,

I am having a little trouble with a macro I recorded to
complete a mail merge. Normally, I work in Access and am a
little ignorant of Word. Any help here would be great.
Here is the code;

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 12/16/2003 by DBW1
'
ActiveDocument.MailMerge.MainDocumentType =
wdMailingLabels
ActiveDocument.MailMerge.OpenDataSource
Name:="C:\Address-data.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:=wdFieldMergeField _
, Text:="""FirstName"""
Selection.TypeText Text:=" "
ActiveDocument.Fields.Add Range:=Selection.Range,
Type:=wdFieldMergeField _
, Text:="""LastName"""
Selection.TypeParagraph
ActiveDocument.Fields.Add Range:=Selection.Range,
Type:=wdFieldMergeField _
, Text:="""Address1"""
ActiveDocument.Fields.Add Range:=Selection.Range,
Type:=wdFieldMergeField _
, Text:="""Address1"""
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeParagraph
Selection.TypeBackspace
ActiveDocument.Fields.Add Range:=Selection.Range,
Type:=wdFieldMergeField _
, Text:="""Address1"""
Selection.TypeParagraph
ActiveDocument.Fields.Add Range:=Selection.Range,
Type:=wdFieldMergeField _
, Text:="""City"""
Selection.TypeText Text:=" "
ActiveDocument.Fields.Add Range:=Selection.Range,
Type:=wdFieldMergeField _
, Text:="""State"""
Selection.TypeText Text:=" "
ActiveDocument.Fields.Add Range:=Selection.Range,
Type:=wdFieldMergeField _
, Text:="""PostalCode"""
WordBasic.MailMergePropagateLabel
End Sub

The problem seems to be generated from the last
line "WordBasic.MailMergePropagateLabel". I have checked
my references and they look normal. The error states the
command is unavailable.

Any ideas?

Thank you all in advance,
David
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi David,

I am puzzled as to why you would try and use a macro to create a label type
mailmerge main document, rather than just create the main document, save it,
and then use it in your macro.

There is nothing wrong with the

WordBasic.MailMergePropagateLabel

by itself. What I do not see anywhere in your code is where the type of
label is selected. I believe that is why you are getting the "command not
available" messsage. Having just tested it, the macro recorder does not
pick up the step where you select the type of labels that you are going to
use. However, If you use the recorder when using Tools>Letters and
Mailings>Labels>Select Label Type>New Document, it does generate code such
as the following:

Application.MailingLabel.DefaultPrintBarCode = False
Application.MailingLabel.CreateNewDocument Name:="AOne 28171",
Address:="" _
, AutoText:="ToolsCreateLabels3", LaserTray:=wdPrinterTractorFeed, _
ExtractAddress:=False, PrintEPostageLabel:=False, Vertical:=False

If you insert the code that you generate in this way, at the beginning of
the code that you already have, then it will work. The following did:

Application.MailingLabel.DefaultPrintBarCode = False
Application.MailingLabel.CreateNewDocument Name:="AOne 28171",
Address:="" _
, AutoText:="ToolsCreateLabels3", LaserTray:=wdPrinterTractorFeed, _
ExtractAddress:=False, PrintEPostageLabel:=False, Vertical:=False

ActiveDocument.MailMerge.MainDocumentType = wdMailingLabels

ActiveDocument.MailMerge.OpenDataSource Name:= _
"C:\Documents and Settings\DKR\My Documents\My Data
Sources\desidata.rtf" _
, 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:=wdFieldMergeField _
, Text:="""FirstName"""
WordBasic.MailMergePropagateLabel

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top