Sign in to follow this  
Followers 0
Laurent

Pass/retrieve parameters to Excel & Word Macro

6 posts in this topic

#1 ·  Posted (edited)

Hello,

I have to admit I'm newbie with AutoIt (find it really cool anyway), and I already searched the forum for an answer to my problem ... but couldn't find what I'm looking for :rolleyes:

So my problem is in fact the following --> Is it possible to pass some parameters from within an AutoIt Script to an Excel file macro, and after execution and closure, retrieve those parameters back into the script to be able to pass them to a Word Macro for execution ?

Here's some code I've tried ... I'm able to launch & execute both macros, but the parameters are always empty :-(

Local $DateTreated = ""
Local $AutoTreat = ""
Local $DraftOrSend = ""
Local $LogFileLocation = ""
Local $strExcelMacroName = "Treatment"
Local $strWordMacroName = "Treatment"

MsgBox(0, "Affichage", $DateTreated & " " & $AutoTreat & " " & $DraftOrSend & " " & $LogFileLocation)

#include <ExcelCOM_UDF.au3>  ; Include the Excel collection

$oExcel = ObjCreate("Excel.Application")                   ; Create an Excel Object
$oExcel = _ExcelBookOpen ("C:\Backup and Personal files\Macros\GenCust_Tri_Pudo CH_Automated.xls")
$oExcel.Visible = 1                                        ; Let Excel show itself
$oExcel.Application.Run($strExcelMacroName , $DateTreated, $AutoTreat, $DraftOrSend, $LogFileLocation)                                      ; Add a new workbook

MsgBox(0, "Affichage", $DateTreated & " " & $AutoTreat & " " & $DraftOrSend & " " & $LogFileLocation)

$oExcel.Quit                                               ; Quit Excel  

MsgBox(0, "Affichage", $DateTreated & " " & $AutoTreat & " " & $DraftOrSend & " " & $LogFileLocation)

#include <Word.au3>

MsgBox(0, "Affichage", $DateTreated & " " & $AutoTreat & " " & $DraftOrSend & " " & $LogFileLocation)

$oWordApp = _WordCreate ("C:\Backup and Personal files\Macros\GenCust_Fax_Pudo CH.dot")

MsgBox(0, "Affichage", $DateTreated & " " & $AutoTreat & " " & $DraftOrSend & " " & $LogFileLocation)

_WordMacroRun ($oWordApp, $strWordMacroName , $DateTreated, $AutoTreat, $DraftOrSend, $LogFileLocation)
_WordQuit ($oWordApp, 0)

would be great if someone could assist me here :-)

regards

Laurent.

Edited by Laurent

Share this post


Link to post
Share on other sites



I tried the following without success.

#include <Word.au3>

#cs (Test Macro)
    Sub MacroTestByRef(ByRef v_Arg)
        v_Arg = "After"
    End Sub
#ce

$vArg = "Before"
$sFilePath = @ScriptDir & "\ByRef.doc"

$oWordApp = _WordCreate($sFilePath, 0, 0)
__WordMacroRun($oWordApp, "MacroTestByRef", $vArg)
_WordQuit($oWordApp, 0)
ConsoleWrite($vArg & @CR)

Func __WordMacroRun(ByRef $o_object, $s_MacroName, ByRef $v_Arg1)
    $o_object.Run($s_MacroName, $v_Arg1)
EndFunc   ;==>__WordMacroRun

It appears AutoIt does not support ByRef in this case. This would be a good feature request.

Share this post


Link to post
Share on other sites

Thanks anyway big_daddy - I already tried several things (but I'm far away from beeing a "specialist") without any success neither :-(

I've now found a turn around for my case here --> I'm starting the Word Macro from within the Excel macro, passing to it the needed parameters ... it's working fine like this, but it's not as "clean" as I would have expected ... as you wrote, it would be a good feature to add :rolleyes:

regards

Laurent.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

@ Laurent's script

I am trying to make a script with excel functions but my Autoit doesn't know:

#include <ExcelCOM_UDF.au3>

Have you download this after the instalation? (i cann't found it in the download, and i have also Autoit 3)

Edited by UQOII

[center]uqoii.nl[/center]

Share this post


Link to post
Share on other sites

I am trying to make a script with excel functions but my Autoit doesn't know:

#include <ExcelCOM_UDF.au3>

Have you download this after the instalation? (i cann't found it in the download, and i have also Autoit 3)

There's a link for it here.

Share this post


Link to post
Share on other sites

Thanks big_daddy for replying for me ... by chance you were here so UQOII didn't had to wait 'till I came back in the forum :whistle:

Regards

Laurent

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