Solved

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

Posted on 2014-07-24
2
138 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Viewers will learn the basics about Excel 2013’s new Flash Fill feature.
Viewers will learn the basics of formula auditing in Excel 2013.

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now