+ Reply to Thread
Results 1 to 2 of 2

Executing a macro at a defined time

Hybrid View

  1. #1
    Registered User
    Join Date
    11-06-2008
    Location
    UK
    Posts
    5

    Executing a macro at a defined time

    I have a worksheet that is used to update daily events. I currently have a macro which is operated manually to send a copy of the worksheet to a defined mailing list.
    I would like to automate this process so that the worksheet is mailed at a defined time each day.
    I tried the following:
    Private Sub Workbook_Open()
     
        Application.OnTime TimeValue("16:16:00"), "Mail_sheets"
     
    End Sub
    But it doesn't seem to work?

    CW
    Last edited by VBA Noob; 02-13-2009 at 02:03 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Executing a macro at a defined time

    Hello Celtic Warrior,

    If you are using a VBA macro to send the email using Outlook from Excel, you can to do this way...
    'Written: October 19, 2008
    'Author:  Leith Ross
    'Summary: Delays sending an email until a certain Date-Time using Outlook.
    
    Sub DelaySendingEmail()
    
      Dim Msg As String
      Dim olApp As Object
      Dim olEmail As Object
      Dim SendAt As String
      Dim SendTo As String
      Dim Subj As String
      
        SendTo = "LeithRoss@gmail.com"
        Subj = "Delayed Email test"
        Msg = "No message."
        SendAt = "10/19/2008 12:30am"     'Date-Time must be in this format
        
          On Error Resume Next
            Set olApp = GetObject(, "Outlook.Application")
            If Err = 429 Then
              Err.Clear
              Set olApp = CreateObject("Outlook.Application")
            End If
          On Error GoTo 0
          olApp.Session.Logon
          
          Set olEmail = olApp.CreateItem(olMailItem)
            With olEmail
              .DeferredDeliveryTime = SendAt
              .To = SendTo
              .Subject = Subj
              .Body = Msg
              .Send
            End With
                
        olApp.Session.Logoff
    
        Set olApp = Nothing
        Set olEmail = Nothing
        
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1