You could try a splash screen approach.
Create a new worksheet, say StartUp
and make it look something like this:
In this picture I have hidden gridlines, etc., changed the background and the font, then included two rectangles linked to subs.
The way the subs work:
1) In a standard code module (which contains the Report
sub that you want to (sometimes) run), I have a variable declared at the top of the module as:
Public TimeOut As Boolean
2) In the code module for my startup sheet I have these two subs (linked to the corresponding shapes):
Sub RunReport()
Sheets("StartUp").Visible = xlSheetHidden
TimeOut = False
Report 'sub to launch
End Sub
Sub UseWorkbook()
Sheets("StartUp").Visible = xlSheetHidden
TimeOut = False
End Sub
3) In the module for ThisWorkbook
I have:
Private Sub Workbook_Open()
Dim start As Double
TimeOut = True
Sheets("StartUp").Visible = xlSheetVisible
Sheets("StartUp").Activate
start = Timer
Do While Timer < start + 60
DoEvents
If TimeOut = False Then Exit Sub
Loop
Sheets("StartUp").Visible = xlSheetHidden
Report
End Sub
When you open the workbook the Open
event is fired, displaying the splash screen. This Workbook_Open
sub then enters a 60-second loop, monitoring the variable TimeOut
. If it ever becomes false (by a splash-screen button being pressed) -- the sub ends (with the event handlers for the shapes hiding the splash screen). Otherwise after 60 seconds the splash screen is automatically hidden and the Report
sub automatically run.
Final Remark: the DoEvents
is needed to monitor the TimeOut
variable and allow for the other event handlers to fire, so you wouldn't want to simply sleep for 60 seconds. Nevertheless, you can still use the excellent suggestion of @teepee by introducing 1 second sleeps in the middle of the Do-While
loop. It is probably enough to check TimeOut
once a second.
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
in your code? – teepeeApplication.OnTime
to start countdown and closing out the UserForm. – PatricK