View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 10,593
Default .onaction, passing arguments

I have never understood why anyone wants to set a parameter value in an
onaction, because it is static, so it defeats the objectives of parameters.
However, that being so, this is how to do it

.OnAction = "'mymacro ""hello""'"

A better way in my view is to test with the macro some of the control button
properties, like so

Sub mymacro()
With Application.CommandBars.ActionControl
If .Tag < "" Then
MsgBox .Tag
End If
End With
End Sub


which you can set dynamically in the code like so

With Application.CommandBars("Standard").Controls("Test ")
If somevalue 17 Then
.Tag = "hello"
Else
.Tag = "goodbye"
End If
End With


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Neal Zimm" wrote in message
...
Hi All,
Am just getting into toolbars and custom menus that will call macros.
Docum says in summary, for toolbars, .onaction = "MyMacro" 'with xxx
and
_ end with not shown.

Well, I've got macros whose function varies via arguments.
e.g. call RealMacro(arg1)

Haven't yet read Walkenbach's chapter on menus, but as a heads-up I
tried
.onaction = Run Macname "arg value" but of course it errored out.

So, it seems unless there's a better way, that I'll have to have an
"intermediate"
call whe (in sorta pseudo code)
.onaction = "MyMacA"
.onaction = "MyMacB"

sub MyMacA()
call RealMacro("arg value A")
end sub

sub MyMacB()
call RealMacro("arg value B")
end sub

Am I getting warm ?

--
Neal Z