Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-07-24
2
Medium Priority
?
160 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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.
: Microsoft Office Collaborate for free and online versions of Microsoft  Word, Excel, Powerpoint, OneNote, Onedrive , Email, Calendar etc. In short we can say that Microsoft office is a suite of servers, applications and services developed by  Micr…
Viewers will learn the different options available in the Backstage view in Excel 2013.
Viewers will learn how to apply various conditional formatting in Excel 2013.

782 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