Call Word macro from Excel

Naozumi

New Member
Joined
May 31, 2010
Messages
4
I am trying to call a word macro from in excel. If I ignore any variables, then it works. However, when I include any variables, it fails.

Public Sub doQuote()

'Create the quote
Dim wdApp As Object
Dim wdDoc As Object
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Open(ThisWorkbook.Path & "\NCR Form.dot")
wdApp.Visible = True

'This Works
wdApp.Run ("test")

'These Fail (Object doesnt support this property)
wdApp.Run ("test(""Str"")")
wdApp.Run "test(""Str"")"
S = "str"
wdApp.Run ("test(S)")
wdApp.Run "test(S)"

'This wont compile (.NET way of doing things)
wdApp.Run ("test", "Str")

Set wdApp = Nothing
Set wdDoc = Nothing

End Sub


Basically I've tried everything I can find and nothing seems to work as wanted. Any help would be awesome.

Thanks
 
Last edited:

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Have you tried removing the parentheses?
Code:
wdApp.Run "test", "Str"
 
Upvote 0
Well it worked fine for me.

Are you sure the problem is in the posted code?

Could it perhaps be in the Word VBA code?
 
Upvote 0
Word doc

Sub test(myStr As String)
z = MsgBox("Worked")
End Sub

And what version of office are you using? Im using both 2010, and 2003 (Win7 XPMode)


EDIT
Works under 2003. Client uses only 2003 so that is good. Thanks. Do you know any 2010 compatible versions though?
 
Last edited:
Upvote 0
That's about exactly the same code I used to test it.

I'm running Word 2000, but I don't know if this is a version issue.

I've definitely not heard of this sort of functionality being changed.:)

Though when I come to think of it, could the problem be that you have 2 different versions installed.

What Word library is checked when you goto Tools>References...
 
Upvote 0
Works under 2003. Don't understand why it fails under 2010.

In the XP Virtual machine, its v11 (offfice 03)
In Windows 7, its v14 (office 2010)

Same code. Only works under 03. Not the only thing to change between the 2 though. Can't make toolbars anymore, so probably just some compatibility thing. Annoying, but atleast it works just now. Thanks Norie.
 
Upvote 0

Forum statistics

Threads
1,221,602
Messages
6,160,739
Members
451,669
Latest member
Peaches000

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