Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Can't get parameters on macros working...

Consider a checkbox created at run-time something like this:

Dim CheckBox As Shape
Set CheckBox=Me.Shapes.AddFormControl(xlCheckBox, 0,0,100,0)
CheckBox.OnAction="'ClickHandler'"

Sub ClickHandler()
Debug.Print "Clicked!"
End Sub

Run the code and click on the checkbox and the ClickHandler runs.

However, I'd love to be able to pass a parameter and I've read several posts
whereby it says you can set OnAction to 'ClickHandler "Hello"' and it will
pass "Hello" as the paramater:

Dim CheckBox As Shape
Set CheckBox=Me.Shapes.AddFormControl(xlCheckBox, 0,0,100,0)
CheckBox.OnAction="'ClickHandler ""Hello""'"

Sub ClickHandler(Text)
Debug.Print "Clicked!"
End Sub

This just doesn't work - the code runs without complaining but ClickHandler
never gets called when you click.

What am I doing wrong?

Thanks, Rob.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Can't get parameters on macros working...

Should work in xl2000 SR1 and earlier. Believe support for this was dropped
with the latest Service Release of xl2000 and later versions. I don't have
any official word on this, but based on past postings in this group of what
versions were used by people having problems.

--
Regards,
Tom Ogilvy

"Rob Nicholson" wrote in message
...
Consider a checkbox created at run-time something like this:

Dim CheckBox As Shape
Set CheckBox=Me.Shapes.AddFormControl(xlCheckBox, 0,0,100,0)
CheckBox.OnAction="'ClickHandler'"

Sub ClickHandler()
Debug.Print "Clicked!"
End Sub

Run the code and click on the checkbox and the ClickHandler runs.

However, I'd love to be able to pass a parameter and I've read several

posts
whereby it says you can set OnAction to 'ClickHandler "Hello"' and it will
pass "Hello" as the paramater:

Dim CheckBox As Shape
Set CheckBox=Me.Shapes.AddFormControl(xlCheckBox, 0,0,100,0)
CheckBox.OnAction="'ClickHandler ""Hello""'"

Sub ClickHandler(Text)
Debug.Print "Clicked!"
End Sub

This just doesn't work - the code runs without complaining but

ClickHandler
never gets called when you click.

What am I doing wrong?

Thanks, Rob.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Can't get parameters on macros working...

Should work in xl2000 SR1 and earlier. Believe support for this was
dropped
with the latest Service Release of xl2000 and later versions. I don't

have

Ahh that might explain it - we're on the latest service pack.

Cheers, Rob.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Can't get parameters on macros working...

Try:

CheckBox.OnAction = "'ClickHandler Hello'"

--

Vasant

"Rob Nicholson" wrote in message
...
Consider a checkbox created at run-time something like this:

Dim CheckBox As Shape
Set CheckBox=Me.Shapes.AddFormControl(xlCheckBox, 0,0,100,0)
CheckBox.OnAction="'ClickHandler'"

Sub ClickHandler()
Debug.Print "Clicked!"
End Sub

Run the code and click on the checkbox and the ClickHandler runs.

However, I'd love to be able to pass a parameter and I've read several

posts
whereby it says you can set OnAction to 'ClickHandler "Hello"' and it will
pass "Hello" as the paramater:

Dim CheckBox As Shape
Set CheckBox=Me.Shapes.AddFormControl(xlCheckBox, 0,0,100,0)
CheckBox.OnAction="'ClickHandler ""Hello""'"

Sub ClickHandler(Text)
Debug.Print "Clicked!"
End Sub

This just doesn't work - the code runs without complaining but

ClickHandler
never gets called when you click.

What am I doing wrong?

Thanks, Rob.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Can't get parameters on macros working...

Actually it would be:

Sub SetOnAction()
ActiveSheet.CheckBoxes(1).OnAction = _
"'ClickHandler ""Hello""'"

End Sub

Sub ClickHandler(sStr)
MsgBox sStr
End Sub

"'ClickHandler Hello'" comes up with a blank message box.

Tested. and works. Excl 2000 SR-1 US English Windows 2000 Pro

--
Regards,
Tom Ogilvy


"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Try:

CheckBox.OnAction = "'ClickHandler Hello'"

--

Vasant

"Rob Nicholson" wrote in

message
...
Consider a checkbox created at run-time something like this:

Dim CheckBox As Shape
Set CheckBox=Me.Shapes.AddFormControl(xlCheckBox, 0,0,100,0)
CheckBox.OnAction="'ClickHandler'"

Sub ClickHandler()
Debug.Print "Clicked!"
End Sub

Run the code and click on the checkbox and the ClickHandler runs.

However, I'd love to be able to pass a parameter and I've read several

posts
whereby it says you can set OnAction to 'ClickHandler "Hello"' and it

will
pass "Hello" as the paramater:

Dim CheckBox As Shape
Set CheckBox=Me.Shapes.AddFormControl(xlCheckBox, 0,0,100,0)
CheckBox.OnAction="'ClickHandler ""Hello""'"

Sub ClickHandler(Text)
Debug.Print "Clicked!"
End Sub

This just doesn't work - the code runs without complaining but

ClickHandler
never gets called when you click.

What am I doing wrong?

Thanks, Rob.








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Can't get parameters on macros working...

Thanks, Tom ... I was too hasty! :-)

Regards,

Vasant.

"Tom Ogilvy" wrote in message
...
Actually it would be:

Sub SetOnAction()
ActiveSheet.CheckBoxes(1).OnAction = _
"'ClickHandler ""Hello""'"

End Sub

Sub ClickHandler(sStr)
MsgBox sStr
End Sub

"'ClickHandler Hello'" comes up with a blank message box.

Tested. and works. Excl 2000 SR-1 US English Windows 2000 Pro

--
Regards,
Tom Ogilvy


"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Try:

CheckBox.OnAction = "'ClickHandler Hello'"

--

Vasant

"Rob Nicholson" wrote in

message
...
Consider a checkbox created at run-time something like this:

Dim CheckBox As Shape
Set CheckBox=Me.Shapes.AddFormControl(xlCheckBox, 0,0,100,0)
CheckBox.OnAction="'ClickHandler'"

Sub ClickHandler()
Debug.Print "Clicked!"
End Sub

Run the code and click on the checkbox and the ClickHandler runs.

However, I'd love to be able to pass a parameter and I've read several

posts
whereby it says you can set OnAction to 'ClickHandler "Hello"' and it

will
pass "Hello" as the paramater:

Dim CheckBox As Shape
Set CheckBox=Me.Shapes.AddFormControl(xlCheckBox, 0,0,100,0)
CheckBox.OnAction="'ClickHandler ""Hello""'"

Sub ClickHandler(Text)
Debug.Print "Clicked!"
End Sub

This just doesn't work - the code runs without complaining but

ClickHandler
never gets called when you click.

What am I doing wrong?

Thanks, Rob.








  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Can't get parameters on macros working...

Tested. and works. Excl 2000 SR-1 US English Windows 2000 Pro

Doesn't work on SP-3 :-(

Sub Init()
While Shapes.Count
Shapes(1).Delete
Wend
Dim Checkbox As Shape
Set Checkbox = Shapes.AddFormControl(xlCheckBox, 200, 200, 100, 0)
Checkbox.OnAction = "'Sheet1.ClickHandler ""Hello""'"
End Sub

Sub ClickHandler(Text)
MsgBox "ClickHandler: " & Text
End Sub

The code doesn't complain when Init is run but that click handler just
doesn't fire. Remove the parameter and have a simple Sub ClickHandler() and
it works fine.

Anyway, found a workaround: Application.Caller can be used to determine
which checkbox fired the event. So I built a simple Dictionary containing
the parameters, key'd by the checkbox name which I can then lookup using
CheckBoxes(Application.Caller).Name (or something like that).

Cheers, Rob.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
2007/macros not working hughesdm Excel Worksheet Functions 1 April 23rd 09 03:28 PM
Macros not working when file run on a Mac Darby Excel Discussion (Misc queries) 4 November 5th 07 02:49 PM
Macros written in UK not working in US Teresa Excel Discussion (Misc queries) 1 April 19th 07 06:59 PM
Working with Macros - Help needed!!! The Greek Excel Discussion (Misc queries) 2 November 19th 06 05:39 PM
Advise, please, how to get the following macros working: LikBez Excel Programming 0 August 19th 03 08:53 AM


All times are GMT +1. The time now is 03:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ╘2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"