Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Accessing the text of a form command button from underlying macro

Hi All

I have a Forms command control that my users use to toggle the
visiblity of my legend/key. At the moment my command button's text is
"Toggle Legend" which is exactly what the macro behind it does.

Unfortunately some of my users do not know what toggle means and are
confused. I therefore would like to be able to change the text of my
command button each time it is clicked - from "Show Legend" to "Hide
Legend".

However I cannot see how do do this through the object model.

I can get a handle on the shape:
Dim aShape As Shape
Set aShape = ActiveSheet.Shapes(Application.Caller)

But cannot see how to access the text that lives on the button.

Are form command buttons considering shapes? or some other object?

Any ideas?

Thanks in advance,
Chrisso

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Accessing the text of a form command button from underlying macro

Open the Command control tool Bar and enter Design mode by clicking on the
Triangle Icon. Then right click the button and select Format Control. You
should be able to change the name.

If you were using a VBA Form, then go to View menu and select Properties
window. then select with mouse the button. Change the caption option for
the button in the properties window.

"Chrisso" wrote:

Hi All

I have a Forms command control that my users use to toggle the
visiblity of my legend/key. At the moment my command button's text is
"Toggle Legend" which is exactly what the macro behind it does.

Unfortunately some of my users do not know what toggle means and are
confused. I therefore would like to be able to change the text of my
command button each time it is clicked - from "Show Legend" to "Hide
Legend".

However I cannot see how do do this through the object model.

I can get a handle on the shape:
Dim aShape As Shape
Set aShape = ActiveSheet.Shapes(Application.Caller)

But cannot see how to access the text that lives on the button.

Are form command buttons considering shapes? or some other object?

Any ideas?

Thanks in advance,
Chrisso


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Accessing the text of a form command button from underlying macro

The instruction I gave last time only works when the button isd created.
Instead
Left click and then right click the button. Select Properties and change
the caption.
"Chrisso" wrote:

Hi All

I have a Forms command control that my users use to toggle the
visiblity of my legend/key. At the moment my command button's text is
"Toggle Legend" which is exactly what the macro behind it does.

Unfortunately some of my users do not know what toggle means and are
confused. I therefore would like to be able to change the text of my
command button each time it is clicked - from "Show Legend" to "Hide
Legend".

However I cannot see how do do this through the object model.

I can get a handle on the shape:
Dim aShape As Shape
Set aShape = ActiveSheet.Shapes(Application.Caller)

But cannot see how to access the text that lives on the button.

Are form command buttons considering shapes? or some other object?

Any ideas?

Thanks in advance,
Chrisso


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Accessing the text of a form command button from underlying macro

On 15 Sep, 13:58, Joel wrote:
Open the Command control tool Bar and enter Design mode by clicking on the
Triangle Icon. Then right click the button and select Format Control. You
should be able to change the name.

If you were using a VBA Form, then go to View menu and select Properties
window. then select with mouse the button. Change the caption option for
the button in the properties window.



"Chrisso" wrote:
Hi All


I have a Forms command control that my users use to toggle the
visiblity of my legend/key. At the moment my command button's text is
"Toggle Legend" which is exactly what the macro behind it does.


Unfortunately some of my users do not know what toggle means and are
confused. I therefore would like to be able to change the text of my
command button each time it is clicked - from "Show Legend" to "Hide
Legend".


However I cannot see how do do this through the object model.


I can get a handle on the shape:
Dim aShape As Shape
Set aShape = ActiveSheet.Shapes(Application.Caller)


But cannot see how to access the text that lives on the button.


Are form command buttons considering shapes? or some other object?


Any ideas?


Thanks in advance,
Chrisso- Hide quoted text -


- Show quoted text -


Sorry Joel - I was not clear in my message.

I want to change the text on my button from VBA each time it is
clicked. I know how to change it manually.

Chrisso

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,489
Default Accessing the text of a form command button from underlying macro

Hi,

Try this,

Sub ToggleLegend()

Dim shpTemp As Shape

With ActiveSheet.Shapes(Application.Caller)
If .TextFrame.Characters.Text = "Show Legend" Then
.TextFrame.Characters.Text = "Hide Legend"

' other code

Else
.TextFrame.Characters.Text = "Show Legend"

' other code

End If
End With

End Sub

Cheers
Andy

Chrisso wrote:
Hi All

I have a Forms command control that my users use to toggle the
visiblity of my legend/key. At the moment my command button's text is
"Toggle Legend" which is exactly what the macro behind it does.

Unfortunately some of my users do not know what toggle means and are
confused. I therefore would like to be able to change the text of my
command button each time it is clicked - from "Show Legend" to "Hide
Legend".

However I cannot see how do do this through the object model.

I can get a handle on the shape:
Dim aShape As Shape
Set aShape = ActiveSheet.Shapes(Application.Caller)

But cannot see how to access the text that lives on the button.

Are form command buttons considering shapes? or some other object?

Any ideas?

Thanks in advance,
Chrisso



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Accessing the text of a form command button from underlying ma

It is still the caption
ActiveSheet.CommandButton1.Caption = "Chrisso"

"Chrisso" wrote:

On 15 Sep, 13:58, Joel wrote:
Open the Command control tool Bar and enter Design mode by clicking on the
Triangle Icon. Then right click the button and select Format Control. You
should be able to change the name.

If you were using a VBA Form, then go to View menu and select Properties
window. then select with mouse the button. Change the caption option for
the button in the properties window.



"Chrisso" wrote:
Hi All


I have a Forms command control that my users use to toggle the
visiblity of my legend/key. At the moment my command button's text is
"Toggle Legend" which is exactly what the macro behind it does.


Unfortunately some of my users do not know what toggle means and are
confused. I therefore would like to be able to change the text of my
command button each time it is clicked - from "Show Legend" to "Hide
Legend".


However I cannot see how do do this through the object model.


I can get a handle on the shape:
Dim aShape As Shape
Set aShape = ActiveSheet.Shapes(Application.Caller)


But cannot see how to access the text that lives on the button.


Are form command buttons considering shapes? or some other object?


Any ideas?


Thanks in advance,
Chrisso- Hide quoted text -


- Show quoted text -


Sorry Joel - I was not clear in my message.

I want to change the text on my button from VBA each time it is
clicked. I know how to change it manually.

Chrisso


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Accessing the text of a form command button from underlying macro

On 15 Sep, 14:43, Andy Pope wrote:
Hi,

Try this,

Sub ToggleLegend()

Dim shpTemp As Shape

With ActiveSheet.Shapes(Application.Caller)
If .TextFrame.Characters.Text = "Show Legend" Then
.TextFrame.Characters.Text = "Hide Legend"

' other code

Else
.TextFrame.Characters.Text = "Show Legend"

' other code

End If
End With

End Sub

Cheers
Andy



Chrisso wrote:
Hi All


I have a Forms command control that my users use to toggle the
visiblity of my legend/key. At the moment my command button's text is
"Toggle Legend" which is exactly what the macro behind it does.


Unfortunately some of my users do not know what toggle means and are
confused. I therefore would like to be able to change the text of my
command button each time it is clicked - from "Show Legend" to "Hide
Legend".


However I cannot see how do do this through the object model.


I can get a handle on the shape:
Dim aShape As Shape
Set aShape = ActiveSheet.Shapes(Application.Caller)


But cannot see how to access the text that lives on the button.


Are form command buttons considering shapes? or some other object?


Any ideas?


Thanks in advance,
Chrisso- Hide quoted text -


- Show quoted text -


Thanks Andy - that will do nicely. Chrisso

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
macro attached to command button - VBA form Roy Gudgeon[_2_] Excel Discussion (Misc queries) 2 March 16th 10 12:44 PM
Accessing the underlying OLE data abhimanyu Excel Programming 0 February 28th 07 03:01 PM
Command Button vs Form Button Bri[_3_] Excel Programming 2 February 3rd 06 08:18 AM
Accessing Active X command button properties greg Excel Programming 2 July 20th 04 09:04 PM
Command Button vs Form Button T K Excel Programming 4 August 26th 03 07:26 PM


All times are GMT +1. The time now is 04:00 PM.

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

About Us

"It's about Microsoft Excel"