Parsing paramters

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

Hi NG

Sometime when using callbacks e.g. .OnAction then it could be nice to pass
some parameters to the macro. Does anyone have a suggestion on how that
might be accomplished.

Mark
 
Mark,

I think you sent me on a wild goose chase there. You don't mean Callbacks do
you? As to passing a parameter to OnACtion, that is easily achieved with

Here is an example from my system

sAction = "'PERSONAL.XLS'!'PasteComments ""Bob"'"
.OnACtion = sACtion

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
There is a method to do it, but it is unsupported and I believe xl2002 and
beyond don't support it anymore.

Sub SetAction()
Selection.OnAction = "'mymacro 1, 2'"
End Sub


Sub mymacro(one, two)
MsgBox one & " " & two
End Sub

so enclose the string in single quotes.
 
With Commandbars("Mybar").Controls.Add(type:=msoControlButton)
.Caption = "MS1"
.OnAction = "MySub"
.Parameter = 1
End with
With Commandbars("Mybar").Controls.Add(type:=msoControlButton)
.Caption = "MS2"
.OnAction = "MySub"
.Parameter = 2
End With

Then in your sub:

Public Sub MySub()
For i = 1 to CommandBars.ActionControl.Parameter
'Do stuff once or twice
Next i
End Sub

or

Public Sub MySub()
If CommandBars.ActionControl.Parameter = 1 Then
'Do Stuff for button MS1
ElseIF CommandBars.ActionControl.Parameter = 2 Then
'Do Stuff for button MS2
Else
MsgBox "Don't Understand " & _
CommandBars.ActionControl.Parameter
 
Back
Top