Time Pop-Up after every 10 min - new

RuggerBiker

New Member
Joined
Aug 5, 2021
Messages
4
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
I found this code posted here in 2014. I got it to work, sort of. But it doesn't run automatically when opening the document. Macros are enabled, and it's a trusted document. I have to open the Visual Basic Editor and start it. Perhaps something has changed since 2014.

Since it's so old, I've made a new post.
VBA Code:
Public RunWhen As Double
Public Const cRunIntervalSeconds = 10 ' <------- This number represents 10 seconds. Change to 600 for 10 minutes
Public Const cRunWhat = "Timer"  ' the name of the procedure to run
 
 Sub StartTimer()
    RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
    Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
        Schedule:=True
End Sub
 Sub Timer()
   
    MsgBox "10 seconds has elapsed", , "Time is up"   ' Change 10 seconds to whatever you want that matches the time set in line 2
    
    StartTimer  ' Reschedules/Resets the procedure to run again and again
End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Welcome to the MrExcel Message Board.

You see how the Timer() sub routine reschedules the timer? You just need to schedule the timer when you Open the workbook.

Open the Thisworkbook class module, and schedule the timer by calling the StartTimer in the Workbook_Open event procedure as shown below:
VBA Code:
Private Sub Workbook_Open()
    ' Schedule the timer for the initial execution
    StartTimer
End Sub
 
Upvote 0
Welcome to the MrExcel Message Board.

You see how the Timer() sub routine reschedules the timer? You just need to schedule the timer when you Open the workbook.

Open the Thisworkbook class module, and schedule the timer by calling the StartTimer in the Workbook_Open event procedure as shown below:
VBA Code:
Private Sub Workbook_Open()
    ' Schedule the timer for the initial execution
    StartTimer
End Sub
Thank you, but it's still not working. Here is a screen shot:
 
Upvote 0
image
 

Attachments

  • Screen Shot 2021-08-05 at 1.41.10 PM.jpg
    Screen Shot 2021-08-05 at 1.41.10 PM.jpg
    106.6 KB · Views: 34
Upvote 0
Remove Class1 class module. You don't need it.
Double click on the Thisworkbook class at the bottom of the Microsoft Excel Objects category in the VBAProject.
Copy and paste that code into that class module.

It will look like the following:
1628196507431.png
 
Upvote 0
Solution
Thisworkbook and Sheet in the VBAProject are the existing class modules that belong to the workbook and worksheets objects as default in the workbook.

These class modules contain various associated event procedures that you can use to catch various events on the objects.

Workbook_Open() event procedure is triggered when the workbook is opened.

Basically, you should use the Workbook_Open event procedure to call the other macros that you want to execute when the workbook is opened.

Note: I suggest looking at the other event procedures (click on the second drop-down that currently shows Open in the code window) and get familiarized with them. Those are magical events that you'll realize that you can use for many other purposes during the development.

1628196867431.png
 
Upvote 0
It works! I'm new to VBA and knowing where to put everything has been the challenge.
Thank you.
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,930
Members
452,367
Latest member
TePunaBloke

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