SubMenu .action argument

J

jgwphansen

I have created a customized menu with submenus which I want to have run
the sub procedure "EnterInvoice" that passes a variable "VendorName"
from the .OnAction part of the With SubMenu CommandButton to the macro.
I have declared the argument in the sub as:

Sub EnterInvoice(ByVal VendorName)

but can't figure out how to do it.

I've tried different versions of the following but can not get the
syntax to work.

Set SubMenuItem = MenuItem.Controls.Add(Type:=msoControlButton)
With SubMenuItem
.Caption = "Co&mmissary Order"
.OnAction = "EnterInvoice"(Commissary)
End With

Ideas?

Thanks
 
J

Jim Cone

Assigning an argument worked well in xl97,
but the rules were changed in later versions. It can still work,
but I just quit using arguments with the OnAction property.
One way to get an argument to a sub, is to assign it to
the Tag property of the control...

With SubMenuItem
.Caption = "Co&mmissary Order"
.OnAction = "EnterInvoice"
.Tag = "Commissary"
End With

Then in the called sub, extract the Tag from the "ActionControl"...

Sub EnterInvoice()
Dim VendorName as String
VendorName = Application.CommandBars.ActionControl.Tag
'More
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



I have created a customized menu with submenus which I want to have run
the sub procedure "EnterInvoice" that passes a variable "VendorName"
from the .OnAction part of the With SubMenu CommandButton to the macro.
I have declared the argument in the sub as:

Sub EnterInvoice(ByVal VendorName)
but can't figure out how to do it.
I've tried different versions of the following but can not get the
syntax to work.
Set SubMenuItem = MenuItem.Controls.Add(Type:=msoControlButton)
With SubMenuItem
.Caption = "Co&mmissary Order"
.OnAction = "EnterInvoice"(Commissary)
End With
Ideas?
Thanks
 

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