VBA Send email doesn't work

Kra

Board Regular
Joined
Jul 4, 2022
Messages
160
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I am trying to set up an VBA to send email at specific date and time. But I cannot properly set
VBA Code:
.DeferredDeliveryTime
line. It returns Run-time error 440, The object does not support this method. Any ideas how to fix it?

Cell with date is custom formatted as DD-MMM-YYYY, and cell with hour is formatted as Time
VBA Code:
Sub RectangleRoundedCorners4_Click()

Dim OutlookApplication As Object
Dim OutlookMail As Object
Dim ws As Worksheet
Dim Ads As String
Dim Subj As String
Dim Body As String
Dim DelDate As Date
Dim DelHour As Integer
Dim DelMin As Integer


    Set OutlookApplication = CreateObject("Outlook.Application")
    Set OutlookMail = OutlookApplication.CreateItem(0)
    Set ws = ActiveSheet
     Ads = ws.Cells(4, 2).Value
     Subj = ws.Cells(7, 2).Value
     Body = ws.Cells(4, 9).Value
     DelDate = ws.Cells(10, 6).Value
     DelHour = Hour(ws.Cells(12, 6).Value)
     DelMin = Minute(ws.Cells(12, 6).Value)
   

    With OutlookMail
        .To = Ads
        .CC = ""
        .BCC = ""
        .Subject = "REMINDER: " & Subj
        .Body = Body
        .DeferredDeliveryTime = DelDate & DelHour
    End With
   
    Set OutlookMail = Nothing
    Set OutlookApplication = Nothing
       
End Sub


Book1
ABCDEFGHIJKLMNOPQ
1
2
3Addres:Text:
4email@email.comWhy are you not working?!
5
6Subject (will automatically begin with REMINDER)
7Test
8
9Date:
1015-Nov-2022
11Time:
1210:00
13
14
15
16
17
18
19
20
21
22
23
Sheet1
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Instead of:

VBA Code:
     DelDate = ws.Cells(10, 6).Value
     DelHour = Hour(ws.Cells(12, 6).Value)
     DelMin = Minute(ws.Cells(12, 6).Value)

    .DeferredDeliveryTime = DelDate & DelHour

try:
VBA Code:
 DelDate = CDate(ws.Cells(10, 6).Value + ws.Cells(12, 6).Value)
.DeferredDeliveryTime = DelDate
 
Upvote 0
Solution
Instead of:

VBA Code:
     DelDate = ws.Cells(10, 6).Value
     DelHour = Hour(ws.Cells(12, 6).Value)
     DelMin = Minute(ws.Cells(12, 6).Value)

    .DeferredDeliveryTime = DelDate & DelHour

try:
VBA Code:
 DelDate = CDate(ws.Cells(10, 6).Value + ws.Cells(12, 6).Value)
.DeferredDeliveryTime = DelDate
Thank you, it works!
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top