+ Reply to Thread
Results 1 to 10 of 10

Seeking VBA code to open MailMerge .docm from Excel

  1. #1
    Registered User
    Join Date
    05-06-2016
    Location
    Melbourne, Australia
    MS-Off Ver
    2013
    Posts
    41

    Seeking VBA code to open MailMerge .docm from Excel

    Hi,

    My second question for the evening is: how do I open a Word document that is a mail merge template and also has a macro in it?
    All attempts so far using code found on the internet have resulted in a range of errors.

    On opening, the Word document requires permission for a SQL command to run, and if it's opened for the first time - permission to enable macros.

    At this stage, all I want to achieve is to open it.

    Any help appreciated...

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,786

    Re: Seeking VBA code to open MailMerge .docm from Excel

    Please show the code you are using to open the Word document for a complete answer. I have not tested this but this appears to be the solution:
    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    05-06-2016
    Location
    Melbourne, Australia
    MS-Off Ver
    2013
    Posts
    41

    Re: Seeking VBA code to open MailMerge .docm from Excel

    Thanks for the reply, I appreciate it, but I'm sorry - I've got no code to show you, I don't know what early or late bindings are, and I have no clue as to how to go about applying the code snippet you offered. I haven't made any progress.

    Using other people's code found on the internet I can open the mail merge document, but the window that prompts the SQL command to run does not show (see below) and the data from the excel database has not been loaded.

    "Opening this document will run the following SQL command:
    'SELECT * FROM MailMerge_DB$'
    Data from your database will be placed in the document. Do you want to continue?" (Yes/No)


    I'm in over my head.
    Last edited by melpa; 04-16-2024 at 12:07 PM.

  4. #4
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,055

    Re: Seeking VBA code to open MailMerge .docm from Excel

    You can suppress this message (security alert) with VBA, but it'll have the effect of responding "No", which isn't what you want.

    I think the only option is to disable the alert in the registry.

    Opening this will run the following SQL command

  5. #5
    Registered User
    Join Date
    05-06-2016
    Location
    Melbourne, Australia
    MS-Off Ver
    2013
    Posts
    41

    Re: Seeking VBA code to open MailMerge .docm from Excel

    Thank you, again, for coming up with the answer, ByteMarks. I read the linked article and it speaks to the problem exactly.

    As my project is something I’m making for a friend this solution is not an option for me, but it is a solution nonetheless.

  6. #6
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,055

    Re: Seeking VBA code to open MailMerge .docm from Excel

    It might be possible to use vba to manipulate the registry key. So you'd disable it before the mailmerge and re-enable it after.

  7. #7
    Registered User
    Join Date
    05-06-2016
    Location
    Melbourne, Australia
    MS-Off Ver
    2013
    Posts
    41

    Re: Seeking VBA code to open MailMerge .docm from Excel

    Unbelievable! It worked! Thank you! The link you provided and the extra hints held the key. And in the end the code is not complex.

    This works to open the MailMerge document and run the macro inside it:
    Please Login or Register  to view this content.
    However, I find the idea of giving a friend an excel workbook that has the power to manipulate the registry of their computer a little terrifying: Have you got any pointers as how to safeguard the code so it doesn't do any damage?

  8. #8
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,055

    Re: Seeking VBA code to open MailMerge .docm from Excel

    What are the routines CreateRegistryKey DeleteRegistryKey ?
    I was thinking more of changing the value rather than deleting the key itself.

  9. #9
    Registered User
    Join Date
    05-06-2016
    Location
    Melbourne, Australia
    MS-Off Ver
    2013
    Posts
    41

    Re: Seeking VBA code to open MailMerge .docm from Excel

    I may be using the wrong terminology...
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by melpa; 04-17-2024 at 10:48 AM.

  10. #10
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,055

    Re: Seeking VBA code to open MailMerge .docm from Excel

    The presence of the key disables the check so that's ok. For a moment I thought it was the other way round.

    I don't think there's too much to safeguard against. You can let your friend know, or build in some msgbox and make sure any error handling deletes the key to reinstate the check.
    E.g.

    Please Login or Register  to view this content.

+ 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. Open mailmerge at a specific item
    By MartinGM in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-20-2023, 12:52 AM
  2. Mailmerge to Excel - Stuck once the vba code opens word document
    By Siddo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-30-2022, 03:22 AM
  3. Print an Excel sheet to a Word docm file?
    By brucemc777 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-14-2017, 12:28 PM
  4. Configuring code to pull data from .docm user forms
    By samuelle in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-15-2016, 12:38 PM
  5. Open Word docm from Excel: Test if already open? Word errors?
    By brucemc777 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-21-2014, 01:02 PM
  6. Copy Excel Range into Word, without Normal.docm save prompt
    By Graham1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-03-2011, 02:52 PM
  7. MailMerge is over, but template stays open and give error msgs.
    By leaning in forum Word Programming / VBA / Macros
    Replies: 1
    Last Post: 08-10-2011, 05:56 PM

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