Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing parameters to OnAction Handler

Status
Not open for further replies.

jgillin

Programmer
Oct 22, 2003
82
US
I'm trying to pass parameters to an OnAction event hanlder in PowerPoint (for a menu item command). I obtained a syntax for this that was supposed to work, but doesn't seem to be.
The syntax is as follows:

EditSubmenuItem.OnAction = "'EditSubmenuAction """ & strParameter & """'"

Unfortunately, it just doesn't work. I simply have a MsgBox inside the sub to see if it's being called, but it isn't. The sub is defined as such:

Sub EditSubmenuAction(ByVal strParameter As String)
MsgBox "Submenu Action", vbOKOnly
End Sub

If I set the OnAction handler normally (without passing in a parameter it works fine).

Does anyone have any suggestions on how to change the syntax to make it work?
Thanks,
Jeff
 
Hi Jeff,

Clicking on a menu item or an icon does not allow for the passing of parameters so why do you want to do this?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
The way it can work is to make the parameter external to procedure, execute 'OnAction' once, and instead of passing parameter here, set current parameter string, for instance:

Public strParameter As String

Sub SetOnAction()
EditSubmenuItem.OnAction = "EditSubmenuAction"
End Sub

Sub SetParam()
strParameter = "Test string"
End Sub

Sub EditSubmenuAction()
MsgBox strParameter, vbOKOnly, "Submenu Action"
End Sub

combo
 
thx combo,
I did this along the lines you mentioned (setting a global variable for use as the parameter). Great idea.
 
It turns out setting a global property didn't work after all. I wasn't thinking straight at the time. Since I'm adding multiple submenu items in a loop, the global variable just gets overwritten each time.

Instead, what I did was to set the "Tag" property of the control when creating it to keep the parameter information, and used Application.CommandBars.ActionControl to get a reference to the control that was clicked (from within the OnAction handler), and then accessed the Tag property from that reference.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top