The previous example used the Parameter property of the control on the menu to store information to be passed to the OnAction macro, and pointed out that you can also use the Tag property. If you have more than two items of information to pass, it is more convenient to use a macro procedure that has input parameters.
Say you wanted to pass three items of data, such as a product name and its cost and selling price. The macro might look like the following:
Sub ShowProduct(sName As String, dCost As Double, dPrice As Double)
MsgBox "Product: " & sName & vbCr & _
"Cost: " & Format(dCost, "$0.00") & vbCr & _ "Price: " & Format(dPrice, "$0.00")
To execute this macro from a command bar control, you need to assign something like the following code to the OnAction property of the control:
'ShowProduct "Apple", 3, 4'
The entire expression is enclosed in single quotes. Any string parameter values within the expression are enclosed in double quotes. To define this as the OnAction property of a control referred to by an object variable, ctl, for example, you need to use the following code:
ctl.OnAction = "'ShowProduct ""Apple"", 3, 4'"
The mix of single and double quotes is tricky to get right. The entire string is enclosed in double quotes, and any internal double quotes need to be shown twice.
Was this article helpful?