Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Button To change Caption

Posted on 2012-09-06
5
Medium Priority
?
629 Views
Last Modified: 2012-09-06
Hello All,

Needed possible feedback here……There is a button (a non activeX ) button in the worksheet. I don’t want to use activeX buttons because of potential resizing issues when placed on worksheet (which I have encountered before)

So for this non-activeX button – things need to happen:
It will have a text caption “Option On” when I click on it, that text on the button now shows “Option Off”

How to accomplish that? Considering it’s a non-activeX button on a worksheet….
dummyButton.xlsx
0
Comment
Question by:Rayne
  • 3
  • 2
5 Comments
 

Author Comment

by:Rayne
ID: 38374319
Also if its possible to toggle between two different  background color as well
0
 
LVL 23

Expert Comment

by:irudyk
ID: 38374352
I don't believe there is a way to change the background of the button, although you could change the font or style of the text (e.g. bold).

From the sample file you provided, try adding the following macro code to change the text of the button:
Sub Button1_Click()
    Dim objCell As Range
    Set objCell = ActiveCell
    ActiveSheet.Shapes.Range(Array("Button 1")).Select
    If Selection.Characters.Text = "Option Off" Then Selection.Characters.Text = "Option On" Else Selection.Characters.Text = "Option Off"
    objCell.Select
    Set objCell = Nothing
End Sub

Open in new window

0
 
LVL 23

Accepted Solution

by:
irudyk earned 2000 total points
ID: 38374362
Alternative code to toggle the text between bold and regular:
Sub Button1_Click()
    Dim objCell As Range
    Set objCell = ActiveCell
    ActiveSheet.Shapes.Range(Array("Button 1")).Select
    If Selection.Characters.Text = "Option Off" Then
        Selection.Characters.Text = "Option On"
        Selection.Characters(Start:=1, Length:=9).Font.FontStyle = "Regular"
    Else
        Selection.Characters.Text = "Option Off"
        Selection.Characters(Start:=1, Length:=10).Font.FontStyle = "Bold"
    End If
    objCell.Select
    Set objCell = Nothing
End Sub

Open in new window

0
 

Author Comment

by:Rayne
ID: 38374368
Perfect, this will work perfect. Thank you irudyk for the superfast reply :)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post, we will learn to set up the Group Naming policy and will see how it is going to impact the Display Name and the Email addresses of the Group.
If Skype for Business came with your office 2016 or office 365 installation, you may find that it's almost impossible to either disable or remove it. The application will often launch with each start of Windows, even when explicitly configured not t…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question