ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Parsing paramters (https://www.excelbanter.com/excel-programming/290736-parsing-paramters.html)

Mark[_36_]

Parsing paramters
 
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



Bob Phillips[_6_]

Parsing paramters
 
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)

"Mark" wrote in message
...
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





Tom Ogilvy

Parsing paramters
 
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.

--
Regards,
Tom Ogilvy


"Mark" wrote in message
...
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





JE McGimpsey

Parsing paramters
 
With Commandbars("Mybar").Controls.Add(type:=msoControl Button)
.Caption = "MS1"
.OnAction = "MySub"
.Parameter = 1
End with
With Commandbars("Mybar").Controls.Add(type:=msoControl Button)
.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


In article , "Mark"
wrote:

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




All times are GMT +1. The time now is 07:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com