Sign in to follow this  
Followers 0
Doc Poster

Passing parameters to Word VBA macros

6 posts in this topic

All my searches in forum posts has not revealed how to pass parameters to macros in Word 2000 VBA. Here is a sample module in Word.

CODE
Public Sub ShowMe(Optional strText As String = "")

MsgBox "AutoIt says: " & strText

End Sub

And the companion AutoIt code:

$oWord = ObjGet("","Word.Application")
If @error = 1 or $oWord = 0 Then
    MsgBox(0,"","Failed to access Word")
Else
    $sMacro = "AutoItTest.ShowMe"
    $oWord.Application.Run($sMacro)
EndIf
oÝ÷ Ù8Z·
+ƬÀn¶Ü¢êìxÛh¥«,v¬¶¸§Èr§ëazX§zÚ-çèZ0x"µö¢Æ®¶­s`b33c·4Ö7&òÒgV÷C´WFôEFW7Bå6÷tÖRgV÷C²fײ6"3BfײgV÷C´VÆÆògV÷C²fײ6"3B

I've tried many variations, all with no result. Help!

Share this post


Link to post
Share on other sites



Here's the AutoIt COM syntax for .Run()

$oWord.Application.Run($sMacro, $Param1, $Param2, $Param3, ...)

-S


(Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent]

Share this post


Link to post
Share on other sites

I can't believe it was that simple. Argh! I couldn't find any documentation (at least in reference to AutoIt) to show that syntax. Thank you so much Locodarwin!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

The best documentation for the Word object model comes right out of Word's VBA helpfiles.

Open Word, hit ALT+F11 to get to VBA, then hit F2 to bring up the object browser, then type in your query. In your case, I looked up the word "Run" and looked through the list until I found Application -> Run, at which point I right clicked on it and selected "Help."

I guess the key to converting VBA to AutoIt is to remember that the biggest difference is in how you use variables (e.g. the dollar sign). For the most part, methods, properties, and collections work in AutoIt just like they do in VBA - meaning, once you understand the nuances you can work with just about any Office object practically as-is.

Of course, you may already know that VBA documentation and much more is available via MSDN, which will inevitably become very important to you as you continue working with the Office object models:

http://msdn2.microsoft.com/en-us/office/aa905497.aspx

Highly recommended if you're not already using it.

-S

Edited by Locodarwin

(Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent]

Share this post


Link to post
Share on other sites

Now I feel like a dork, because I did check VBA help when I was trying to figure this out and saw exactly what you're talking about. My mistake was that I thought the procedure name and parameters had to all be inside one parameter in AutoIt, as follows:

$sMacro = "Interact.AutoItDone, Success"
    $oWord.Application.Run($sMacro)

Of course we're all idiots at times. :) Live and learn. Thanks again.

Share this post


Link to post
Share on other sites

My mistake was that I thought the procedure name and parameters had to all be inside one parameter in AutoIt, as follows:

Believe me, I've made bolder mistakes than that while trying to get COM working with AutoIt. :)

-S


(Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0