Connecting to Word Merge Doc

cvincent

Board Regular
Joined
Aug 28, 2011
Messages
66
I have an Excel 2010 worksheet, with a macro to open Word 2010 and merge the data into a letter. It works fine the first time I use it after opening Excel. But after that, it won't work again until I close out Excel and re-open. Any ideas why this is happening?

Even though Word is not open, the error message reads:
Error has occurred: The Microsofe Office Access database engine cannot open or write to the file. It is already opened exclusively by another user, or you need permission to view and write its data.

Run time error 4198: Command failed

The macro opens the merge document, but does not merge. It hangs up here:
wordMailMerge.OpenDataSource Name:=excelPath, SQLStatement:="SELECT * FROM `'ON HOLD$'`"

Thank you for your assistance.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Vincent,

Can you explain the situation a bit clearly on what exactly you are trying to do?
Is that you wanna trying to send the Excel data into a word letter or something else?
 
Upvote 0
Skeptical,
The process automatically merges data from an Excel spreadsheet into a Word merge document. There are 6 different Word merge documents. The macro selects the correct Word document based on the data entered in the Excel spreadsheet. It worked fine for 5 of the letters, but for some reason would not work for a new letter that was created. The letter is named "HOLD letter", and the spreadsheet is named "ON HOLD".

I did some research, however, and found that if I enter a wait time, it will run. Seems strange to me, but it works:

wordPath = ThisWorkbook.Path & "\HOLD letter.doc"
Set wordApp = CreateObject("Word.Application")
Set wordDoc = wordApp.Documents.Open(wordPath)
Set wordMailMerge = wordDoc.MailMerge

Application.Wait (Now + TimeValue("0:00:0000000001"))

wordMailMerge.OpenDataSource Name:=excelPath, SQLStatement:="SELECT * FROM `'ON HOLD$'`"

wordMailMerge.Execute
wordDoc.Close
wordApp.Visible = True
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top