Solved

Change a CommandButton caption during a called routine from A to B then back to A

Posted on 2014-07-24
2
144 Views
Last Modified: 2014-07-25
Hello Experts:
As written, I am stymied as to how to do the following:
Using a command button on a sheet to delete user 671 possible entries (to clear the user entries for reuse)  with the intent to
1) change the caption while the called macro runs and then
2) return the caption to its earlier text...
2a) when the called macro completes its routine, and/or
2b) when the called macro is killed (if the user hits the [Esc] key)
Here's what I have so far:
==================================
Private Sub CommandButton1_Click()
'Resets Scores to zero by erasing 671 cells on 176 rows
With CommandButton1
       If .Caption = "Click to Clear all ''X'' entries" Then
           .Caption = "macro is running & deleting ''X'' entries"
         ElseIf .Caption = "macro is running & deleting ''X'' entries" Then
          .Caption = "Click to Clear all ''X'' entries"
       End If
       Call clearXentries  
  End With
End Sub
========================================
Do I have to place the entire called macro within the CommandButton1_Click() routine or is there another way to get the caption to change during the clearXentries macro 5-minute runtime?
Thanks
Berry
0
Comment
Question by:Berry Metzger
2 Comments
 
LVL 10

Accepted Solution

by:
FamousMortimer earned 500 total points
ID: 40219239
Hi,

I think you might just be missing a DoEvents which will update the button caption.  Also, make sure that screen updating is not off.  If you do turn it off, you will have to toggle it on and off again in the ToggleCaptionn sub.  See my example below...

Option Explicit

Private Sub CommandButton1_Click()
    'Resets Scores to zero by erasing 671 cells on 176 rows
    With CommandButton1
        ToggleCaption (True)
        Call clearxentries
        ToggleCaption (False)
    End With
End Sub

Private Sub ToggleCaption(ByVal IsRunning As Boolean)
    'Application.ScreenUpdating = True
    If IsRunning Then
        CommandButton1.Caption = "macro is running & deleting ''X'' entries"
    Else
        CommandButton1.Caption = "Click to Clear all ''X'' entries"
    End If
    'Application.ScreenUpdating = False
    DoEvents
End Sub

Open in new window

0
 

Author Closing Comment

by:Berry Metzger
ID: 40220164
Thanks for your solution! It works, as I needed it to, with no modification required.  
Berry
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Viewers will learn the basics of formula auditing in Excel 2013.
Viewers will learn a basic relationship technique in Power Pivot for Excel 2013.

756 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