Problem with opening a word document via VBA

PeterP

New Member
Joined
Apr 18, 2008
Messages
4
Hi

I am new to using VBA and would be grateful for advice. I am trying to put a simple command button on a spreadsheet that would open a word document that I want to use for mail-merge purposes. I am using the 2000 versions of both Word & Excel.

I have tried using the following code (picked from a number of advice sites!) but I get an error message "Automation error: The server threw an exception" when trying to run the code. Any help to get it working would be greatly appreciated!

Sub Button1_Click()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open("C:\LetterTemplate.doc")
End Sub


Many thanks
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Further to my query, I have discovered that the References list that opens with my version of Excel has Microsoft Word 10.0 Object Library rather than the 9.0 version. Could this be causing the problem? If so is there any way that I can download Microsoft Word 9.0 Object Library?

Thanks again
 
Upvote 0
Don't set a reference, and adjust your code:

Code:
Sub Button1_Click()
    Dim wrdApp As Object
    Dim wrdDoc As Object
    Set wrdApp = CreateObject("Word.Application")
    wrdApp.Visible = True
    Set wrdDoc = wrdApp.Documents.Open("C:\LetterTemplate.doc")
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,990
Messages
6,175,817
Members
452,672
Latest member
missbanana

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