Open word file from excel VBA (Office 2010)

BigDelGooner

Board Regular
Joined
Aug 17, 2009
Messages
197
Hi all

I was using the following code within an AddIn that I created which was working fine with office 2003..

Sub Open_FundNoteTemplate()
Set Wordapp = CreateObject("word.Application")
Wordapp.documents.Open "\\lon0306.london.schroders.com\dfs\data\dta\SIM_SPF\Investment\Investment Selection\Fund Research & Documentation\__FUND NOTE TEMPLATES\YYYY-MM-DD Fund Note - Fund_Name.doc"
Wordapp.Visible = True
End Sub

...however since switching to Office 2010 I get a '4198' run-time error with the message 'Command failed'. Interesting when I step through the code in VBA it works fine, it's just when the code is executed from the dropdown menu that I get this error.

Any suggestions?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Thank you for the reply.

Unfortunately the document I am opening is still a .doc file...this also doesn't explain why it opens the file when stepping through the code but not when executed through the drop down menu.

Any more ideas guys and girls?
 
Upvote 0
Can you clarify what exactly you mean by "when the code is executed from the dropdown menu"?
 
Upvote 0
Sorry...this code is part of an Excel AddIn that I have created and the code I am referring to is when a user hits a button on the AddIn drop down menu that I have created.

Coincidentally I have just solved the issue, well found a workaround at least. I have entered an application.wait line that delays the code by 1 second after setting the wordapp object and this seems to work.

Thanks for your help guys.
 
Upvote 0
Hi BigDelGooner,

I have had a system working for many years that opened Word and copied stuff from Excel and pasted to Word.

Now back in January we moved to Office 2010 and the creating of the Word document refused to work ( or that's what I thought). But it would work fine if I stepped through the vba code. I finally put a msgbox right before the SET statement:

Code:
        MsgBox "Creating Word Document"
        On Error Resume Next
        Set wrdApp = GetObject(, "Word.Application")
        If wrdApp Is Nothing Then
        ....

This has solved the problem. I guess it allows Word to open up and get the (SAS) Addins that are being brought in, which cause Word to take longer to open.

The msgbox worked for me, but I will try to Application.Wait line.

Thanks
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,823
Members
452,946
Latest member
JoseDavid

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