Consulting

Results 1 to 4 of 4

Thread: How do I use Application.OnTime to open a userform in Outlook?

  1. #1

    How do I use Application.OnTime to open a userform in Outlook?

    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

  2. #2
    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/developer...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.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    613
    Location
    Deleted
    Last edited by Logit; 12-17-2017 at 02:32 PM.

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •