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
 
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
 
Upvote 0

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,214,889
Messages
6,122,097
Members
449,065
Latest member
albertocarrillom

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