Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Word VBA Discuss using VBA to program Word.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Word VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 6th, 2007, 03:55 PM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default error in word VBA to automate creation of mailing

hello,
I'm trying to automate the creation of mailing labels where the source data in an .xls worksheet.
I have the below VBA code that I created first with the macro recorder in word then edited some to put in the Directory and Filename code that I've used successfully in some Excel VBA and VB 6.0 code.
Now I'm having trouble getting the code to work. I run it and I get the error:

Run-time error '509':

This command is not available
and the code execution stops on the line:

WordBasic.MailMergePropagateLabel

Can anyone help me get past this error so the code will run successfully.

thanks in advance,
david

Code:
Dim Directory, Filename As String

    Directory = "C:\My Documents\MonthEndMailingLabels\"
    Filename = Dir(Directory & "*.xls")
'MsgBox Directory & Filename
    ActiveDocument.MailMerge.MainDocumentType = wdMailingLabels
    ActiveDocument.MailMerge.OpenDataSource Name:= _
        Directory & Filename, _
        ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
        AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
        WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
        Format:=wdOpenFormatAuto, Connection:= _
        "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=Directory & Filename;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password" _
        , SQLStatement:="SELECT * FROM `Untitled$`", SQLStatement1:="", SubType:= _
        wdMergeSubTypeAccess
    ActiveDocument.Fields.Add Range:=Selection.Range, Type:= _
        wdFieldAddressBlock, Text:= _
        "\f ""<<_COMPANY_" & Chr(13) & ">><<_STREET1_" & Chr(13) & ">><<_STREET2_" & Chr(13) & ">><<_CITY_>><<, _STATE_>><< _POSTAL_>>"" \l 1033 \c 0 \e """""
    WordBasic.MailMergePropagateLabel
    With ActiveDocument.MailMerge
        .Destination = wdSendToNewDocument
        .SuppressBlankLines = True
        With .DataSource
            .FirstRecord = wdDefaultFirstRecord
            .LastRecord = wdDefaultLastRecord
        End With
        .Execute Pause:=False
    End With
    Selection.WholeStory
Reply With Quote
  #2 (permalink)  
Old April 4th, 2007, 08:34 AM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can anyone help me with this error?

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automate bookmark creation hogg Word VBA 1 November 12th, 2008 04:35 AM
Automate the process of creation bookmarks in word manish.sharma04 BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 1 March 1st, 2006 10:09 AM
VBA cannot create MS Word Object- ActiveX Error Dolphin Access VBA 0 February 7th, 2005 01:03 AM
Automate vba snap shot report to power point learnvb Access VBA 3 January 6th, 2004 07:06 PM
Mailing list module has error - HELP drfunkie BOOK: ASP.NET Website Programming Problem-Design-Solution 3 September 8th, 2003 12:09 PM



All times are GMT -4. The time now is 05:05 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.