View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Neal Zimm Neal Zimm is offline
external usenet poster
 
Posts: 345
Default .onaction, passing arguments

Bob and Tom, thanks. I won't use the technique, (glad to hear that it's
undocumented, 'cuz I looked pretty hard for it and could not find any.)

To Bob's point, what's 'wrong' with the following?
1. Theoretically, if a macro can be called by .onaction = stuff, or by
another sub, keeping the control testing out of that macro makes it more
'independant'?

2. Are you saying that if a macro has to perform let's say 4 processes,
where much of the code is the same, that I should write 4 subs and NOT vary
the function via an argument?
e.g. In my app it's prudent to control several worksheet, ws, processes,
so I have an array of 'reserved' ws names.
I don't mind a user hiding the ws or shifting its ws name tab to the left
or right, arg = "hide" or "move", but I'd like to draw a line in the sand
when arg = "delete" or arg = "insert".

Thanks for your expertise.
Neal
--
Neal Z


"Tom Ogilvy" wrote:

Just a heads up, (and another reason not to use it)

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

is undocumented and in my experience doesn't work with every version of
excel.

--
Regards,
Tom Ogilvy


"Bob Phillips" wrote:

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