PDA

View Full Version : How do I use Application.OnTime to open a userform in Outlook?



OldCityCat
12-13-2017, 09:26 AM
I have a UserForm designed as a TimeCard in both Outlook 2010 & 2016 which I would like to roll out in January.
For the first month I would like to open the TimeCard at 3 intervals per day 8:00, 12:00 and 4:00
As reminder for the user to Clock-In and Clock-Out.
I tried using Application.OnTime to open the TimeCard without much success.


Public Sub OpenTimeCard()

'Runs a macro at 8:00 AM
Application.OnTime TimeValue("08:00:00"), "UserForm_Initialize"


End Sub

Thank you in advance for any ans all suggestions


OldCityCat

gmayor
12-17-2017, 06:09 AM
Presumably "UserForm_Initialize" is code in your userform? I doubt that your macro will see that. You would need a macro to show the userform, however your code still isn't going to work.

You should consider using Outlook's reminders in association with an Outlook task (or tasks) to trigger an action - see http://www.vboffice.net/en/developers/send-emails-automatically/?mnu=2&cmd=showitem for an example of such use, albeit for a different purpose. Instead of creating an e-mail message, use the task reminder to run the macro to call the userform.

Logit
12-17-2017, 10:08 AM
Deleted

SamT
12-17-2017, 01:59 PM
UserForm_Initialize is Private. Instead, use

Application.OnTime TimeValue("08:00:00"), "StandardModuleName.StartUserForm"

Standard Module Code. Replace "StandardModuleName" above with the name of the module you put this code in. Replace "UserForm1" below with the actual Name of the UserForm

Public Sub StartUserForm()
If Now < TimeValue("12:00:00") Then
Application.OnTime TimeValue("12:00:00"), "StandardModuleName.StartUserForm"
ElseIf Now < TimeValue("16:00:00") Then
Application.OnTime TimeValue("16:00:00"), "StandardModuleName.StartUserForm"
End If

UserForm1.Show
End Sub