Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Have one Macro react to whatever cantrol calls it

Hello,
I had a user ask me if there was a way to create a custom checkbox control
for use in Excel. Dick Kusleika was kind enough to suggest this macro and
it worked with great success.

Sub CheckCircle()

With Sheet1.Shapes(1).TextFrame
If .Characters.Text = Chr$(252) Then
.Characters.Text = ""
Else
.Characters.Text = Chr$(252)
End If
End With

End Sub

The user was very happy and with him not knowing anything about VBA, he
asked if I could modify a spreadsheet for him. Not thinking, I accepted.
Turns out it is actually three specification spreadsheets that each have a
minimum of 100 of such custom checkbox controls.

You can see that this would be beyond tedious to have to make a macro for
each control in the above fashion.

Is there a way to make this ONE macro respond to which ever custom control
that calls it? How can you interrogate what control called the macro?
something like:

iCallingControl=CallingControl(item)
Sheet1.Shapes(iCallingControl).TextFrame

Sad I know but does my problem make sense? Is there a spiffy solution?

Any help would be appreciated.

Jim




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default Have one Macro react to whatever cantrol calls it

Hi Jim,

Is there a way to make this ONE macro respond to which ever custom control
that calls it? How can you interrogate what control called the macro?
something like:


I have an article about this on my site:

http://www.jkp-ads.com/articles/ControlHandler00.htm

Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Have one Macro react to whatever cantrol calls it

Jan, I tried your instructions and I must be doing something wrong.
When I follow your instructions and enter:

Option Explicit

Private WithEvents mobtOption As MSForms.OptionButton

Nothing works beyond that. If I backspace over the MSForms.OptionButton
part and press the space bar after the AS word, I do not see MSForms in the
dropdown.

What do I have to do to get that?

Jim




"Jan Karel Pieterse" wrote in message
...
Hi Jim,

Is there a way to make this ONE macro respond to which ever custom
control
that calls it? How can you interrogate what control called the macro?
something like:


I have an article about this on my site:

http://www.jkp-ads.com/articles/ControlHandler00.htm

Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Have one Macro react to whatever cantrol calls it

I don't seem to have Microsoft Forms 2.0 library listed in my references
list.
Where does one get the library?

"Jan Karel Pieterse" wrote in message
...
Hi Jim,

Is there a way to make this ONE macro respond to which ever custom
control
that calls it? How can you interrogate what control called the macro?
something like:


I have an article about this on my site:

http://www.jkp-ads.com/articles/ControlHandler00.htm

Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default Have one Macro react to whatever cantrol calls it

Hi Jim,

I don't seem to have Microsoft Forms 2.0 library listed in my references
list.
Where does one get the library?


It should be there, it is a default part of Office. Just insert a userform
and remove it again, that will set the reference automatically.

Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Have one Macro react to whatever cantrol calls it

Jan, thanks, I got the MSForms object but I have another problem.
Your example deals with the OptionButton as he
Public Property Set Control(obtNew As MSForms.OptionButton)
Set mobtOption = obtNew
End Property

Mine deals with a Excel shapes (triangle, square, circles, etc) and uses the
text option to add a checkmark. When I type "MSFORMS." I can see your
optionbutton in the dropdown but there is no "shape" option for me to get.
How would I make your example work with a excel shapes?

Thanks

Jim



"Jan Karel Pieterse" wrote in message
...
Hi Jim,

I don't seem to have Microsoft Forms 2.0 library listed in my references
list.
Where does one get the library?


It should be there, it is a default part of Office. Just insert a userform
and remove it again, that will set the reference automatically.

Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default Have one Macro react to whatever cantrol calls it

Hi Jim,

Mine deals with a Excel shapes (triangle, square, circles, etc) and uses the
text option to add a checkmark. When I type "MSFORMS." I can see your
optionbutton in the dropdown but there is no "shape" option for me to get.
How would I make your example work with a excel shapes?


I am inclined to think you cannot. The objects you can create events for are
the ones listed in the dropdown. If your object isn't shown in the list (or as
a member of one of the main entries in that list), it cannot be tied to an
event class.

More generally speaking: only objects that expose their events in the code
window of the worksheet you have placed them on can be automated this way.

You can see what objects can have event code by right clicking the sheet tab,
and selecting "View Code". Then if you click on the lefthand dropdown arrow at
the top of the code editor window, you will see a list of all objects that can
have event code. Selecting any of them will write the default event stub in the
code window and now the righthand dropdown will list the available events. Note
that not all of these events may be available with my technique, MS omitted a
couple of them.

Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default **SOLVED** Have one Macro react to whatever cantrol calls it

Although I didn't get the class version to work as you suggested, I solved
my problem this way. Would have preferred to go the class route but had the
issues I described.

Thanks for the help.



Sub CheckShape()
Set shp = ActiveSheet.Shapes(Application.Caller)

With ActiveSheet.Shapes(Application.Caller).TextFrame

If .Characters.Text = Chr$(162) Then

.Characters.Text = ""

Else

.Characters.Text = Chr$(162)

End If

End With

End Sub





"Jim" <. wrote in message ...
Jan, thanks, I got the MSForms object but I have another problem.
Your example deals with the OptionButton as he
Public Property Set Control(obtNew As MSForms.OptionButton)
Set mobtOption = obtNew
End Property

Mine deals with a Excel shapes (triangle, square, circles, etc) and uses
the text option to add a checkmark. When I type "MSFORMS." I can see your
optionbutton in the dropdown but there is no "shape" option for me to get.
How would I make your example work with a excel shapes?

Thanks

Jim



"Jan Karel Pieterse" wrote in message
...
Hi Jim,

I don't seem to have Microsoft Forms 2.0 library listed in my references
list.
Where does one get the library?


It should be there, it is a default part of Office. Just insert a
userform
and remove it again, that will set the reference automatically.

Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com





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
Non-blocking calls to Excel Macro using OLE Automation BW Excel Programming 5 August 3rd 05 09:13 PM
Attn: Dave P. Question re Pix Calls via Macro DocuMike Excel Discussion (Misc queries) 1 January 10th 05 01:38 AM
one macro calls the other ebony Excel Programming 1 January 7th 04 05:27 AM
Macro Calls lchhat Excel Programming 5 November 14th 03 03:56 PM
"This macro calls that macro, which calls .."-how many? Ed[_9_] Excel Programming 2 November 3rd 03 10:02 PM


All times are GMT +1. The time now is 05:32 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"