Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article will show you how to create an ISO CD-ROM/DVD-ROM image (*.iso), and MD5 checksum signature, for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5). It's a good idea to compare checksums, because many installations fail because of a corr…
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Viewers will learn a basic relationship technique in Power Pivot for Excel 2013.
Viewers will learn the basics of printing in Excel 2013 and how to adjust some common settings.

705 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

19 Experts available now in Live!

Get 1:1 Help Now