+ Reply to Thread
Results 1 to 2 of 2

Run Word Mail Merge From Excel VBA

  1. #1
    Registered User
    Join Date
    05-04-2017
    Location
    Chicago
    MS-Off Ver
    2013 & 2016
    Posts
    22

    Run Word Mail Merge From Excel VBA

    Good morning.

    I have put together some syntax to attempt to run a mail merge from data in my Excel Workbook into Word. I have generated a .doc template with the field names and when I execute this line in my Excel VBA I get an error of o
    This method or property is not avaliable because the document is not a mail merge main document

    Please Login or Register  to view this content.
    What do I need to change in my .doc so that it will work as a mail merge template?

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Run Word Mail Merge From Excel VBA

    Hi SmithStanley1212,

    attempt to run a mail merge from data in my Excel Workbook into Word
    I think this might be the wrong approach. In my experience you need 3 files:
    a. The Excel file running VBA code.
    b. The Word Document with the field names
    c. The Excel Data File that contains the fields.

    Typical VBA code excerpt:
    Please Login or Register  to view this content.
    NOTE: Since this code uses 'Late Binding', Word constants such as wdFormLetters must be defined with their actual values in the code. This is a case where 'Option Explicit' is VERY IMPORTANT.


    It is a best practice to declare all variables. If you misspell a variable in your code, VBA will silently assume it is a Variant variable and go on executing with no clue to you that you have a bug. Go to the VBA development window, click Tools, Options, and check "Require Variable Declaration." This will insert the following line at the top of all new modules:
    Please Login or Register  to view this content.
    This option requires all variables to be declared and will give a compiler error for undeclared variables.

    The files associated with post #9 in the following thread provide a working example and should help you get started:
    http://www.excelforum.com/excel-prog...ml#post4190498

    Lewis

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 01-05-2015, 07:35 AM
  2. Replies: 2
    Last Post: 01-22-2013, 11:37 AM
  3. Mail merge within Excel...not with Word
    By PattiFlick in forum Excel General
    Replies: 10
    Last Post: 01-05-2013, 03:05 PM
  4. Word Mail Merge & Excel
    By Olasin in forum Excel General
    Replies: 2
    Last Post: 11-23-2007, 10:44 AM
  5. mail merge from Excel to Word
    By sumplug in forum Excel General
    Replies: 2
    Last Post: 08-17-2006, 12:20 PM
  6. Replies: 0
    Last Post: 04-20-2006, 04:45 PM
  7. [SOLVED] merge with Word How can I get excel to mail merge zip codes plus 4 correctly?
    By Kathy at Sauder Feeds in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-30-2005, 07:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1