Countdown timer (30 seconds) pop-up message before Macro Run

dinkss

Board Regular
Joined
Aug 25, 2020
Messages
129
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi there,

How can I create a VBA CODE to run COUNTDOWN TIMER - a pop-up message, 30 seconds before Macro will run? I want to have a message displayed like "This schedule will AUTO-UPDATE & AUTO-SAVE in..." before macro will run.

I will appreciate any help.

Thanks guys!
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
VBA Code:
Option Explicit

Sub t()
Dim i As Integer
Dim s As Long
    Sheet1.Range("A1").Value = i
        For i = 30 To 0 Step -1
             Range("A1") = i
             s = Timer + 1
             Do While Timer < s
                DoEvents
            Loop
        Next
End Sub
 
Upvote 0
VBA Code:
Option Explicit

Sub t()
Dim i As Integer
Dim s As Long
    Sheet1.Range("A1").Value = i
        For i = 30 To 0 Step -1
             Range("A1") = i
             s = Timer + 1
             Do While Timer < s
                DoEvents
            Loop
        Next
End Sub
I tried this macro and it doesn't work for me.
 
Upvote 0
It works for me, counts down 30 to 0 in cell A1. It just looks like a "proof of concept" bit of code that you need to adapt to your purpose.
more information required might be:
when will the save macro first run?
after what time interval will it run again and again?
 
Upvote 0
It works for me, counts down 30 to 0 in cell A1. It just looks like a "proof of concept" bit of code that you need to adapt to your purpose.
more information required might be:
when will the save macro first run?
after what time interval will it run again and again?

I need a macro to run before automatic save macro and then to show a pop-up message with countdown timer as I have setup automatic save and update macros to run every 45 minutes. So I need a countdown time pop-up message macro that will show up a message on the screen that auto save and auto update macros will run in 30 seconds to inform user not to enter any information within 30 seconds.
 
Upvote 0
VBA Code:
Option Explicit

Sub t()
Dim i As Integer
Dim s As Long

MsgBox "Auto save and auto update macros will run in 30 seconds.", vbInformation & vbOKOnly, "Please Wait" 

    Sheet1.Range("A1").Value = i
        For i = 30 To 0 Step -1
             Range("A1") = i
             s = Timer + 1
             Do While Timer < s
                DoEvents
            Loop
        Next

'Place a call to your autosave macro here

End Sub
 
Upvote 0
To get the countdown to actually appear in the message box/userform, I found this from JoeMo in 2015 which I could only adapt down to 1 minute. I don't know how to get to 30 seconds and I don't know how to get the timer to start automatically when the userform appears. Press Alt F8 to run the macro:

in a module put this
Code:
Public AllowedTime As Variant
Sub TestUserForm()
AllowedTime = "1" 'InputBox("Enter the time interval to count down in whole minutes - max is 99")
'If AllowedTime = "" Then Exit Sub
'MsgBox "click Start when you are ready to begin"
UserForm1.Show
End Sub
make a userform thus:
userform.PNG

in sheet 1 put this
Code:
Private Sub UserForm_Initialize()
Dim M As Double, S As Double
M = Int(CDbl(AllowedTime))
S = (CDbl(AllowedTime) - Int(CDbl(AllowedTime))) * 60
With tBx1
    .Value = Format(CStr(M), "00") & ":" & Format(CStr(S), "00")
End With
End Sub
in the code for the button "Start" put this
VBA Code:
Private Sub CommandButton1_Click()
Dim t, E, M As Double, S As Double
'AllowedTime is set in sub 'modTestUserForm' for this user form
t = Timer
Do
'next If-End If protects in case clock was started just before midnight and Timer resets during countdown
    If Timer - t < 0 Then
        Unload UserForm1
        MsgBox "Error encountered - start again"
        Exit Sub
    End If
    E = CDbl(Time) * 24 * 60 * 60 - t 'elapsed time in secs
    M = CDbl(AllowedTime) - 1 - Int(E / 60)
    S = 59 - Round((E / 60 - Int(E / 60)) * 60, 0)
    With tBx1
        .Value = Format(CStr(M), "00") & ":" & Format(CStr(S), "00")
    End With
    DoEvents
Loop Until (Timer - t) / 60 >= CDbl(AllowedTime) Or UserForm1.Visible = False 'i.e. Cancel clicked during countdown
    Unload UserForm1
    Beep
    MsgBox "workbook saved"
End Sub
in the code for button "don't wait - save now" put this
VBA Code:
Private Sub CommandButton2_Click()
Unload UserForm1
ThisWorkbook.Save
End Sub
 
Upvote 0
VBA Code:
Option Explicit

Sub t()
Dim i As Integer
Dim s As Long

MsgBox "Auto save and auto update macros will run in 30 seconds.", vbInformation & vbOKOnly, "Please Wait"

    Sheet1.Range("A1").Value = i
        For i = 30 To 0 Step -1
             Range("A1") = i
             s = Timer + 1
             Do While Timer < s
                DoEvents
            Loop
        Next

'Place a call to your autosave macro here

End Sub
I will try this out! Thanks
 
Upvote 0
I will try this out! Thanks
Hi

I have just seen this post and i need exactly the same function.
The only difference is i would like to create an automatic backup of my file.

Everything works, but...

Is it possible to get the above code/function work without the user should click on "OK" ?
Simply show the information box and then countdown without any interaction from the user ?
 
Upvote 0

Forum statistics

Threads
1,214,883
Messages
6,122,077
Members
449,064
Latest member
MattDRT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top