WD2002: Mail Merge Document Type Is Displayed Incorrectly When You Run Recorded Macro (282588)



The information in this article applies to:

  • Microsoft Word 2002

This article was previously published under Q282588

SYMPTOMS

When you run a recorded macro to create a mail-merge main document for envelopes, the mail-merge main document is not displayed as an envelope main document. However, if you click Main document setup on the Mail Merge toolbar, the document type is displayed as Envelope.

NOTE: This same problem occurs when you run a recorded mail-merge macro for labels.

WORKAROUND

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

For Envelopes

To correct the recorded macro for envelopes, add the following macro code after the MainDocumentType statement:
   ActiveDocument.Envelope.Insert
				
Your recorded macro code should now appear similar to the following sample recorded macro code:
Sub MyEnvelopeMerge()
'
' MyEnvelopeMerge Macro
'
   ActiveDocument.MailMerge.MainDocumentType = wdEnvelopes

   ActiveDocument.Envelope.Insert '<----Add this macro line.

   ActiveDocument.MailMerge.OpenDataSource Name:= _
      "C:\WINDOWS\Desktop\Address.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"""

End Sub
				

For Labels

To correct the recorded macro for labels, add the following macro code after the MainDocumentType statement:
   Application.MailingLabel.CreateNewDocument
				
Your recorded macro code should now look similar to the following example recorded macro code:
Sub MyLabelMacro()
'
' MyLabelMacro Macro
'
   ActiveDocument.MailMerge.MainDocumentType = wdMailingLabels

   Application.MailingLabel.CreateNewDocument '<----Add this macro line.

   ActiveDocument.MailMerge.OpenDataSource Name:= _
      "C:\WINDOWS\Desktop\Address.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"""

   ActiveWindow.ActivePane.VerticalPercentScrolled = 0

   WordBasic.MailMergePropagateLabel

End Sub
				

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbbug kbenvelope kbmacro kbmacroexample kbmerge kbnofix KB282588