PC Review


Reply
Thread Tools Rate Thread

Accessing the text of a form command button from underlying macro

 
 
Chrisso
Guest
Posts: n/a
 
      15th Sep 2007
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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      15th Sep 2007
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
>
>

 
Reply With Quote
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      15th Sep 2007
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
>
>

 
Reply With Quote
 
Chrisso
Guest
Posts: n/a
 
      15th Sep 2007
On 15 Sep, 13:58, Joel <J...@discussions.microsoft.com> 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

 
Reply With Quote
 
Andy Pope
Guest
Posts: n/a
 
      15th Sep 2007
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
>

 
Reply With Quote
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      15th Sep 2007
It is still the caption
ActiveSheet.CommandButton1.Caption = "Chrisso"

"Chrisso" wrote:

> On 15 Sep, 13:58, Joel <J...@discussions.microsoft.com> 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
>
>

 
Reply With Quote
 
Chrisso
Guest
Posts: n/a
 
      15th Sep 2007
On 15 Sep, 14:43, Andy Pope <a...@andypope.info> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro attached to command button - VBA form Roy Gudgeon Microsoft Excel Misc 2 16th Mar 2010 12:44 PM
How to activate command button on form by macro Denis Microsoft Excel Programming 2 24th Oct 2008 08:59 PM
Command Button on Form Macro Emily Microsoft Access 0 6th Dec 2007 06:31 PM
Macro Text on Command Button gone in email =?Utf-8?B?U3VlS3VLdQ==?= Microsoft Word Document Management 4 8th May 2006 11:55 PM
Insert text from command button or macro? Piers Microsoft Access Getting Started 0 1st Oct 2003 08:53 PM


Features
 

Advertising
 

Newsgroups
 


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