Results 1 to 2 of 2

Opening Word mailmerge document from Excel using VBA

Threaded View

  1. #1
    Registered User
    Join Date
    07-31-2013
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    Office 2013
    Posts
    5

    Opening Word mailmerge document from Excel using VBA

    Hi everybody,

    I am fairly new to working with this, but I have managed to create a mailmerge in Word that uses an Excel document to populate several fields.
    It also inserts graphics using INCLUDEPICTURE statements depending on a status that is specified in the Excel file. This will be a Red, Amber or Green circle. Which one of these it should be is stated in a mergefield which reads either RED, AMBER or GREEN. E.g. if value is RED, Word will pick the picture 'RED.png' and insert it. See fields on page 7 in Basic assessment.doc.

    The files are used to created personalised reports based on information that users specify in the Excel file. So the main document a user would work in is the Excel file.
    Ideally I would like to enable users to fire up the merge of fields into Word from the Excel file. I have found code to open the Word document from Excel and placed that under a button in Excel. See the code below, or see the button on worksheet "Final Rating - Recommendation" in Assessment Report Base File SAMPLE.xlsm.

    So here's my question:
    When I open the Word document using Word as one would normally do, a dialog pops up to say that it will link to fields in the Excel file ("Opening this document will run the following SQL command: SELECT * FROM 'MAILMERGEFIELDS'..." - where MAILMERGEFILEDS is the range in Excel I merge from), and update the fields according to the information in the Excel file. But if I use the code in Excel to open the document it wil just open the Word document and not start the mail merge link. This results in a document without updated field values, non-merged, just showing the last version I created and saved.

    Any help to tackle this would be much appreciated!
    Many thanks.

    P.S.: Attached both Worfd and Excel file. Merging won't work with the attached files because they aren't the originals used to create the link.

    ' INCLUDEPICTURE statement I use to insert correct graphic
    {INCLUDEPICTURE "{IF TRUE "<<picture path>>\\{MERGEFIELD Self_awareness}.png" }"\d }

    'COMMAND BUTTON CODE TO OPEN WORD DOCUMENT FROM EXCEL
    Private Sub CommandButton1_Click()
    'Opens a Word Document from Excel
    
    Dim objWord As Object
    
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    
    'Change the directory path and file name to the location
    'of your document
    
    objWord.Documents.Open "D:\HayData\Assessment reports\Basic assessment document MAILMERGE.doc"
    End Sub
    Last edited by BoldCreature; 09-16-2013 at 05:36 AM. Reason: Solved the issue

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Mailmerge from Excel and Word to new word document
    By PooH in forum Word Programming / VBA / Macros
    Replies: 3
    Last Post: 11-12-2011, 05:09 PM
  2. Opening Word document with Excel
    By Mr.Jones in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 01-11-2007, 10:13 AM
  3. Replies: 3
    Last Post: 03-14-2006, 10:20 AM
  4. opening an excel document in word
    By zoot in forum Excel General
    Replies: 4
    Last Post: 07-21-2005, 08:05 AM
  5. Opening Word Document with excel
    By gandgsuarez@zipcon.net in forum Excel General
    Replies: 1
    Last Post: 03-20-2005, 10:24 PM

Tags for this Thread

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