Jump to content
Sign in to follow this  
TripScott

Passing Parameters to Word so they are used by VBA

Recommended Posts

TripScott

I cannot find any answers to this.

My AutoIt script should:

1. AutoIt read a row of data in Excel --> Working

2. Pull a Word document from our document database & open it --> Working

3. Run a Word macro that uses the data from Excel that AutoIt read

I am having trouble with Step 3. When I run the word macro with parameters it doesn't work.

Note: a Word document is opened when I run this.

CODE

#include <Word.au3>

Opt("WinWaitDelay", 250)

Opt("WinTitleMatchMode", 4)

Opt("WinDetectHiddenText", 1)

Opt("MouseCoordMode", 0)

Global $hWnd, $myClip, $style, $GWL_EXSTYLE, $iResponse, $v_Arg1, $v_Arg2, $v_Arg3

Global $FilePath, $oExcel, $title, $myRow, $myColumn, $myECM, $myByPass, $hWndsCREEN2, $hWndsCREEN1

$v_Arg1 = "New"

$v_Arg2 = "6"

$v_Arg3 = "ecm5052895.B"

$oWordApp = ObjGet("", "Word.Application")

$oWordDoc = ObjName("", "Word.Application.Documents")

WinWait("[REGEXPTITLE:^.* - Microsoft Word$]", "")

If Not WinActive("[REGEXPTITLE:^.* - Microsoft Word$]", "") Then WinActivate("[REGEXPTITLE:^.* - Microsoft Word$]", "")

WinWaitActive("[REGEXPTITLE:^.* - Microsoft Word$]", "")

$oWordDoc = WinActivate("[REGEXPTITLE:^.* - Microsoft Word$]", "")

_WordMacroRun($oWordApp, "StartHereDocs", $v_Arg1, $v_Arg2, $v_Arg3)

It does not run the macro when the parameters listed. I does work if I leave them out. But I need the information sent to Word. What am I missing that it isn't running correctly?

That does bring up a 2nd question. How does Word get the parameters? Is there a VBA code for this?

Thanks for any help on either question.

Kristine

Share this post


Link to post
Share on other sites
picaxe

Your word macro should be something like

Function func_name(param1, param2, param3, param4)

check @extended after calling func _WordMacroRun (-1 = Invalid number of parameters)

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.