Link to home
Start Free TrialLog in
Avatar of AZshooter
AZshooter

asked on

Need to export data from Excel 2013 into a Word Doc (Mail Merge) that is based upon an existing .dotx template

I am having trouble getting this to work. I need to make sure I am late-binding objects due to compatibility issues with various Office versions being used by coworkers.

I have an existing .dotx Word template that needs to be used as the basis for the final document. The data is coming from an SQL query of the Excel sheet.

I am finding most of my issues are with the Word aspect. It has to do with whether Word is already running or not, or if there is an open document or not.

Thanks in advance.
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

The standard way of using mailmerge is via the Word user interface. Here you create the 'main' document, i.e. one with mailmerge fields and fixed text. It does not need to be a template in the Word sense, and can be saved as a .docx.

With it open in Word, you click on the Finish & Merge button on the Mailings tab, and the merge takes place.

Are you doing something different? If so what  - and what exactly goes wrong>
Avatar of AZshooter
AZshooter

ASKER

Hello. Thank you for the reply.

Yes, I am looking for the means to do this with a VBA macro in Excel 2013. The workbook stores the inventory of our demo equipment. When a sales-person wants to check it out he prints a request which get populated with the details for a worksheet.

So, in VBA I want to create a new Word document based upon an existing template. Then do the mailmerge with the data from the spreadsheet.

Where I seem to be having problems I think is the new SDI of Office 2013, it used to work very well in 2010. Also, I am trying to late-bind objects in my code now because of variations of Office versions within our group. So, losing IntelliSense probably led to me getting stuff wrong...I'm not that great a programmer.

When this part of my code runs:

    Set wdApp = CreateObject("Word.Application")
    Set wdocSource = wdApp.documents.Add(template:=WordTemplatePath)

Word does not start, nor does a new document get created.

I hope I'm explaining myself clearly.
Thank in advance.
Here is my solution:

    Set wdApp = CreateObject("Word.Application")
    wdApp.Visible = True
    Set wdocSource = wdApp.documents.Add(template:=WordTemplatePath) 'e.g. "R:\demo\public\EVT_DERF_Catalog.dotx"
    wdocSource.Visible = True

Looks like this works for me.
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial