Not getting daily auto email from excel VBA macro

SMS71

New Member
Joined
Jun 15, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hello,
I am writing a macro to send an email daily at 9:30am from an excel by attaching the same excel. While i am able to get the mail when i test run the macro in VBA module window, but i am unable to get the mail daily automatically on the specified time. Below is my code.

*******ThisWorkbook Code********
Private Sub SetOnTime()
Dim Start As Date
Start = DateSerial(2021, 6, 14)
If Date <= Start + 5 Then
Call SendMail
Application.OnTime TimeValue("9:30:00"), "SendMail"
End If
End Sub

***********Module Code************
Public Const MailFunct = "SendMail"
Sub SendMail()
Dim outlookApp As Object
Dim myMail As Object

Set outlookApp = CreateObject("Outlook.Application")
Set myMail = outlookApp.CreateItem(olMailItem)

ThisWorkbook.Save
source_file = ThisWorkbook.FullName

With myMail
.To = "smadhu71@rediffmail.com"
.CC = "smadhu71@rediffmail.com"
.Subject = "Update"
.Body = " "
.Attachments.Add source_file
.Send
End With
End Sub
 

Logit

Well-known Member
Joined
Aug 31, 2016
Messages
4,211
I moved some of the code to the same module as the Email macro. Presently the code is set to display the email. You can edit that to .Send as needed.

It works.

Download : Shared_with_Logit.xlsm
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

SMS71

New Member
Joined
Jun 15, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hi,
Its working. Thank you very much.
 

Forum statistics

Threads
1,144,246
Messages
5,723,215
Members
422,485
Latest member
Tameima

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
Top