Can an argument be passed to a macro assigned to a custom menu item?

  • Thread starter Vincent Boris Arnold
  • Start date
V

Vincent Boris Arnold

Can an argument be passed to a macro assigned to a custom
menu item? If so, how?
 
C

Charles Kenyon

Not directly. You could assign a value to a custom document property and
pull that value with your macro. In that way, your macro does not take a an
argument. You could also have your macro prompt for user input and then use
that input.
 
J

Jezebel

In addition to the mthods Charles suggests, you can also use the menu item's
Parameter and Tag properties. The macro can check ActionControl to determine
which menu item was used to initiate the macro, then read the properties to
get the macro argument values.
 
K

Klaus Linke

Vincent Boris Arnold said:
Can an argument be passed to a macro assigned to a
custom menu item? If so, how?



Hi Vincent,

Not sure what you want to do...
You could use the control's .Parameter or .Tag properties, and evaluate
them in your macro:

Sub TestMacroButton()
' You only need to set the .Parameter or .Tag property once;
' use the control once with the lines un-commented:
' CommandBars.ActionControl.Parameter = "Test Parameter"
' CommandBars.ActionControl.Tag = "Test Tag"
MsgBox CommandBars.ActionControl.Parameter
MsgBox CommandBars.ActionControl.Tag
End Sub

That way, you can use the same macro for several controls.

If the "argument" is some piece of information you need to get from the
user, you could use an InputBox statement in your macro.

Regards,
Klaus
 
K

Klaus Linke

<g> Looks like we are in perfect sync!

Klaus


Jezebel said:
In addition to the mthods Charles suggests, you can also use the menu item's
Parameter and Tag properties. The macro can check ActionControl to determine
which menu item was used to initiate the macro, then read the properties to
get the macro argument values.
 
G

Guest

I understand the macro side now, but how to you specify
the argument in the menu item? This is a custom menu being
created for a template.
 
J

Jezebel

You've had the answer to this twice now. You can't do it directly. Instead
you set the .Tag or .Parameter property of the menu item. The macro reads
that property and uses it as its argument.
 
K

Klaus Linke

I understand the macro side now, but how to you specify
the argument in the menu item? This is a custom menu being
created for a template.

In the macro I posted, you could un-comment the lines at the start of the
macro, and use the control once from the user interface, to set the
..Parameter and .Tag properties of the control.
After that, you could comment out the lines again.

If you had something completely different in mind (such as, say, writing
your own combo box control like the font or font size controls), please
post back.

Regards,
Klaus
 

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