Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Word 2007: Macro in template not available in mail merged document

  • 10-06-2010 4:26pm
    #1
    Registered Users, Registered Users 2 Posts: 7,541 ✭✭✭


    Hey all.

    I have the following issue in Word 2007. I have two files, template.dot - template for the mail merge and data.csv - data for the mail merge. I created the merged document programmatically as follows:

    Sub performMailMerge
    Dim strDataSource
    Dim objWord
    Dim docWord
    Dim wrdApp

    Set wrdApp = CreateObject("Word.Application")

    strDataSource = outputFile

    Set objWord = CreateObject("Word.Application")
    Set docWord = objWord.Documents.Open(templateFile)

    docWord.MailMerge.OpenDataSource strDataSource
    docWord.MailMerge.Destination = 0

    docWord.MailMerge.Execute False
    docWord.Close False

    objWord.Visible = True
    objWord.Activate

    Set objWord = Nothing
    Set docWord = Nothing

    End Sub

    This works fine, but the document created does not contain the macros in the template.dot file. If I create a new document (unmerged) from the template the macros are available.

    How can I create the merged document that also retains the macros from template.dot? I'd prefer not to go near normal.dot to do this.

    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 7,541 ✭✭✭irlrobins


    Ugh, as always I spent nearly a day on a problem and then as soon as I post about it on boards 10 mins later I work out the solution. FFS..

    Anyway, the solution:
    Change Set docWord = objWord.Documents.Open(templateFile)
    to
    Set docWord = objWord.Documents.Add(templateFile)


Advertisement