triggering macros with parameters

J

Jake Williams

Is it possible to trigger a macro with parameters using
vbScript? If so, could you please post the code or
provide a link to the information.
Here is what I am doing thus far...but it will not work
if I have parameters.

Dim WD
Set WD = CreateObject("Word.Application")
WD.Documents.Open "C:\word.Doc"
WD.Run "Project.Module1.Macro1"
WD.Close
 
A

Andrew Cushen

Jake-

One of the definitions of a macro is that it cannot take
parameters. Sorry.

It is possible you could do what you want using a VBA
function, instead of VB Script/Macros, though- but this
depends on where the code is going. If the code is going
to be behind a form, you're out of luck. If, however, you
could add a button to the toolbar and trigger your code
from there, you could use a VBA function, which accepts
parameters. Hit Alt-F11 to open the VBA Editor, then F1
for VBA help, and have a look around.

HTH,

-Andrew
===========================================
 
C

Chad DeMeyer

Jake,

The Run method of the Application object in Word will accept up to 30
parameters. E.g.,

WD.Run "Project.Module1.Macro1", arg1, arg2, ... arg30

where arg1, arg2, etc. are the parameters you wish to send to the procedure
or function. Of course, those parameters need to be defined in the
declaration, e.g.,

Sub MySub(param1 as String, param2 as Integer, ... param30 as Object)

Hope this helps.
Regards,
Chad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top