Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mail Merge Macro

Status
Not open for further replies.

RAxel

MIS
Sep 8, 2005
121
US
I'm curious as to how complex a macro can get. I'm making a macro for a mail merge (from the contacts in my mailbox in Outlook 2003) and getting an error. These are the steps I'm doing:

1. Tools -> Letters and Mailings -> Mail Merge
2. Click Envelope radio button
3. Click Next: Starting Document
4. Click Change document layout radio button
5. Click Envelope options...
6. Leave everything as default and click OK
7. Click Next: Select recipients
8. Click Select from Outlook contacts
9. Choose Contacts Folder... I choose the contact folder in my mailbox, then click Select All, then click OK
10. Click Next: Arrange your envelope
11. Click the middle of the envelope and then click Address Block
12. Leave it as the default and click OK
13. Click Next: Preview your envelopes
14. Click Next: Complete the merge


Now, I could end it here, but I went ahead and hit the print button and changed some settings there to make it even more automated. The place where I'm getting the error is when the <<Address Block>> appears on the screen. What is weird is that the <<Address Block>> should appear AFTER the layout has changed to envelope, but it doesn't. And the <<Address Block>> appears on the top left of the screen, not in the middle where it is supposed too.

Finally, the layout doesn't change to the correct envelope layout and I don't believe Word grabs the contacts from Outlook and that's where I believe the error occurs. Any help is appreciated.

 


Hi,

Please post your code.

Skip,

[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue]
 
Here is the unedited code straight from the recorded macro in word 2003:

Code:
Sub ContactEnvelopeMerge()
'
' ContactEnvelopeMerge Macro
' Macro recorded 10/11/2005 by sean.axel
'
    ActiveDocument.MailMerge.MainDocumentType = wdEnvelopes
    If ActiveWindow.View.SplitSpecial = wdPaneNone Then
        ActiveWindow.ActivePane.View.Type = wdPrintView
    Else
        ActiveWindow.View.Type = wdPrintView
    End If
    ActiveWindow.ActivePane.View.Zoom.PageFit = wdPageFitBestFit
    ActiveWindow.ActivePane.View.Zoom.PageFit = wdPageFitBestFit
    Selection.MoveDown Unit:=wdLine, Count:=2
    ActiveDocument.Fields.Add Range:=Selection.Range, Type:= _
        wdFieldAddressBlock, Text:= _
        "\f ""<<_TITLE0_ >><<_FIRST0_>><< _LAST0_>><< _SUFFIX0_>>" & Chr(13) & "<<_COMPANY_" & Chr(13) & ">><<_STREET1_" & Chr(13) & ">><<_STREET2_" & Chr(13) & ">><<_CITY_>><<, _STATE_>><< _POSTAL_>><<" & Chr(13) & "_COUNTRY_>>"" \l 1033 \c 2 \e ""U"
    With ActiveDocument.MailMerge
        .Destination = wdSendToPrinter
        .SuppressBlankLines = True
        With .DataSource
            .FirstRecord = wdDefaultFirstRecord
            .LastRecord = wdDefaultLastRecord
        End With
        .Execute Pause:=False
    End With
End Sub
 
I just ran that macro, and this time it just said "This method or property is not available because the current mail merge main document needs a data source." But what I don't understand, is that in the recording of the macro, I told it to use my mailbox contacts. I'm guessing word is having a hard time talking to outlook?
 
So I understand that the macro didn't record the fact that I told it to use the contacts in my mailbox as the data source to perform the mail merge. Is there code to physically create a data source that the contacts can get written to, which is then used for the mail merge?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top