PDA

View Full Version : Command Menu bar and OnAction



ILO120
03-12-2009, 07:42 AM
Hi,

I create a menu bar with an array.
So now I'd like ti use the property onAction.
Indeed, when user click on a line about this menu, i'd like to write a label in document.
To do that, i try to use the command Selection.InsertAfer, but I dont know how to do that with onAction and a parameter : myMenuBarArray.

Thanks for your help

fumei
03-12-2009, 09:23 AM
Please post what code you have tried.

.onAction executes an existing Sub. Technically, .onAction is a string parameter. This is passed to VBA and it tries to execute a Sub named with that string. I do not think you can use required parameters. It returns an "Argument not optional" error. This is because .onAction is a string, not a pointer.

I could be wrong. Does anyone know how to pass parameters to .onAction?

ILO120
03-12-2009, 10:09 AM
Thanks to your answer.
After reading you answer, I have another question: is it possible to give to .OnAction a sub with parameter.
Like:
.OnAction="MySub(MyCommandArray(K))"

fumei
03-12-2009, 12:17 PM
Ummm, that is exactly what I asked. I do not think so BECAUSE .onAction is a string, and VBA uses that string as a name.

So

.OnAction="MySub(MyCommandArray(K))"

is telling VBA to look for the Sub:

Sub MySub(MyCommandArray(K))()

This is not a valid name. So, no, I do not think you can pass parameters with .onAction, but again, if someone DOES know how to do so, let us all know.