+ Reply to Thread
Results 1 to 6 of 6

Swap button text

  1. #1
    Forum Contributor
    Join Date
    11-17-2004
    MS-Off Ver
    Office 2016
    Posts
    527

    Swap button text

    I have a forms control (VBA) button that, when clicked, I'd like to test the value written on the button, and perform an action, then change what's written on that button (to show what action was taken). When the button is clicked a second time, I'd like to reverse the process, i.e, test the value written on the button, reverse the previous action, then replace the button text with the original text. Because I cannot know when opening the file what the state of the button is, I feel that each time I press the button I should test the state of the button so that I perform the proper action.

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Swap button text

    Maybe something like this? Assign the macro to the button
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    11-17-2004
    MS-Off Ver
    Office 2016
    Posts
    527

    Re: Swap button text

    When I use this code I get the Variable not defined message with the word "Buttons" highlighted on the second line of code.

  4. #4
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Swap button text

    Maybe post a sample of your workbook. The code should be in a worksheet to work. If you are putting them in a module, you need to reference with that worksheet.buttons. I also attached a sample.
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    11-17-2004
    MS-Off Ver
    Office 2016
    Posts
    527

    Re: Swap button text

    This worked out great. I was a bit confused at first about how the buttons are referenced, but it seems they are Buttons(1) ,(2), (3) etc. in the order they are created on the worksheet rather than by the button number the label says.

  6. #6
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Swap button text

    Hello JimDandy,

    This worked out great.
    As it would seem that you are satisfied with the solution given to you, it would also be great if you mark this Thread as Solved.

    You may also cliclk on the star to the far left at the bottom of the Contributors' Post to add to his/her Reputation.

    Thank you.

    Regards
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Toggle Button to swap link results from another worksheet
    By mochatrpl in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-30-2013, 10:37 PM
  2. [SOLVED] Swap out text in text box based on radio button selection
    By gordco in forum Excel General
    Replies: 2
    Last Post: 12-13-2012, 11:49 AM
  3. [SOLVED] Swap text in a cell complication
    By alexxshadows in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 11-14-2012, 09:06 PM
  4. Text Strings Swap
    By Mzansi in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-29-2005, 07:10 AM
  5. Modify sub to swap text phrases in cells
    By Max in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-07-2005, 08:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1