RE: Displaying a Msgbox 1 hour after the workbook opens

chazrab

Well-known Member
Joined
Oct 21, 2006
Messages
917
Office Version
  1. 365
Platform
  1. Windows
RE: Displaying a Msgbox 1 hour after the workbook opens

This code is in the Workbook Open() event:
Code:
Private Sub Workbook_Open()
If Day(Now) = 10 Then
    MsgBox "Good morning"
else
End if

This works great but displays the MsgBox as soon as soon the workbook is opened. How do I get the MsgBox to appear 1 hour(or, to extend this to a more elaborate solution, any later time specified by an input variable) after the workbook is opened.

Thanks for anyone's help on this.
cr
 
Last edited by a moderator:

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Re: Displaying a Msgbox 1 hour after the workbook opens

Posting your email address is not recommended unless you want to tempt spammers galore!

In ThisWorkbook module
Code:
Private Sub Workbook_Open()
    Dim dTime As Date, timeDelay As Date
    timeDelay = TimeValue("01:00:00")
    If Day(Now) = 10 Then
        dTime = Now + timeDelay
        Application.OnTime dTime, "[COLOR=#b22222]MyMacro[/COLOR]"
    End If
End Sub

In STANDARD module
Code:
Sub [COLOR=#b22222]MyMacro[/COLOR]()
    MsgBox "Hello"
End Sub
 
Upvote 0
Re: Displaying a Msgbox 1 hour after the workbook opens

Posting your email address is not recommended unless you want to tempt spammers galore!

In ThisWorkbook module
Code:
Private Sub Workbook_Open()
    Dim dTime As Date, timeDelay As Date
    timeDelay = TimeValue("01:00:00")
    If Day(Now) = 10 Then
        dTime = Now + timeDelay
        Application.OnTime dTime, "[COLOR=#b22222]MyMacro[/COLOR]"
    End If
End Sub

In STANDARD module
Code:
Sub [COLOR=#b22222]MyMacro[/COLOR]()
    MsgBox "Hello"
End Sub

Thx for helping with this - you answered my issue correctly - display the Msgbox after 1 hour. But what if I wanted to specify ANY time value of timeDelay to use your variable name, from a combo dropdown list or a textbox on a userform within the same application. This timeDelay variable has to be formatted correctly to run the code. That's the issue I'm having now. Thx for any help.
cr
 
Upvote 0
Re: Displaying a Msgbox 1 hour after the workbook opens

Time is a number between 0 and 1 as follows
24 hours = 1
so ...
1 second = 1/(24*60*60)
6 hours = 6/24 = 0.25
12 hours = 12/24 = 0.5
etc

For simplicity make the dropdown values minutes (eg 10, 20, 30 etc)

So ... where D = value selected (in minutes) from dropdown ...
Code:
timeDelay = D/(60*24)

Hopefully the above provides what you need to write the userform code
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,184
Members
452,615
Latest member
bogeys2birdies

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