views:

19

answers:

1

What I'm attempting to do is send an email using VBA in excel though outlook but with a defered send date/time for the next day about 8:30. The code bellow, will send an email fine, it will even send one with a derfered send time even when my workstation is locked, however it seems when i set it to next day 8:30 they just stay in my outbox untill I open them up and hit, I can even open them up and hit send before the defered time and they will send fine, or after and they will send imediatly.

The deferedtime variable passed in is a string formated "dd/mm/yyyy hh:mm:ss" e.g "15/10/2010 08:30:00"

Sub Send_Outlook_Email(Addresses, attach, strSubject, strBody, defertime)

    Dim objOL As Outlook.Application
    Dim msg As Outlook.MailItem

    Set objOL = New Outlook.Application
    Set msg = objOL.CreateItem(olMailItem)
    Dim d As Date

    strEmail = ""
    For i = 0 To UBound(Addresses)
            strEmail = strEmail & Addresses(i) & "; "
    Next
    strEmail = Trim(strEmail)
    With msg
        .To = strEmail
        .subject = strSubject
        .HTMLBody = strBody
            For i = 0 To UBound(attach)
            strAttach = attach(i)
                If Len(strAttach) > 0 And Len(Dir(strAttach)) > 0 Then
                    .Attachments.Add (strAttach)
                End If
            Next
        .DeferredDeliveryTime = defertime
        .Send
    End With

End Sub

Am I missing something important?

A: 

The DeferredDeliveryTime is a property of an Outlook mail message.

If you have an Exchange server, the "delayed sending" will be done by Exchange. If you do not have Exchange your Outlook application needs to be active.

GvS
Yes it's done though an Exchange server, as I've mentioned it will send when my workstation is locked but not when it runs over night. I can run the macro then go into my outbox hit send and then when the delaytime rolls around it will send, likewise when I create the email by hand with a delay time. With this in mind I don't belive it is a problem with the Outlook application being active or Exchange server but with the macro or how the delaytime is passed to Outlook
Anthony