I'm very new to Outlook VBA and coding in general, the rest of my code works correctly but of the different methods I've tried to get the time to change to 9am, it hasn't worked or has removed the preceding DateAdd("d", 2, now) which correctly assigns it for 2 days time. Am I just missing a simple code where "Now" currently is?
replyEmail.DeferredDeliveryTime = DateAdd("d", 2, Now)
Thanks in advance for anyone looking over this.
I've tried using the different DateTime functions, defining certain values as e.g. Date Time("09:00:00")
CodePudding user response:
After playing around for two days, it appears I've stumbled upon my answer.
replyEmail.DeferredDeliveryTime = DateAdd("d", 2, Date) DateAdd("n", 0, #9:00:00 AM#)
My issue was finding the right object and then how to join the two so the function didn't override itself causing only the date or time to be correct, but not both.
I'm sure there is a way to make this look cleaner and if I discover it, I'll post but this does the job for the time being.
CodePudding user response:
Option Explicit
Sub deferredDelivery_2D9H()
Dim mItem As MailItem
Dim d2_9AM As Date
Debug.Print "Date 2 time format......: " & Format(Date 2, "ddddd hh:nn")
d2_9AM = DateAdd("h", 9, Date 2)
Debug.Print "d2_9AM....................: " & d2_9AM
Set mItem = CreateItem(olMailItem)
mItem.DeferredDeliveryTime = d2_9AM
Debug.Print "mItem.DeferredDeliveryTime: " & mItem.DeferredDeliveryTime
mItem.Display
' "Do not deliver before" entry in Options Tracking Properties dialog
'ActiveInspector.CommandBars.ExecuteMso ("DelayDeliveryOutlook")
' Options Tracking Properties dialog
ActiveInspector.CommandBars.ExecuteMso ("MessageOptions")
End Sub