Call outlook mail send vba windows scheduler
A great combination!
To send an Outlook email using VBA and schedule it to run at a specific time using the Windows Task Scheduler, follow these steps:
Step 1: Create a VBA script in Outlook
-
Open Outlook and press
Alt + F11
to open the Visual Basic Editor. -
In the Editor, click
Insert
>Module
to insert a new module. -
Paste the following code into the module:
Sub SendEmail() Dim olApp As New Outlook.Application Dim olMail As MailItem Set olMail = olApp.CreateItem(0) ' 0 = MailItem With olMail .Subject = "Your email subject" .Body = "Your email body" .To = "[email protected]" .Send End With Set olMail = Nothing Set olApp = Nothing End Sub
This code creates a new Outlook email, sets the subject, body, and recipient, and then sends the email.
Step 2: Schedule the VBA script using the Windows Task Scheduler
- Open the Task Scheduler: You can do this by searching for "Task Scheduler" in the Start menu, or by typing
taskschd.msc
in the Run dialog box (Windows key + R). - Create a new task:
- In the Task Scheduler, click
Create Basic Task
in the right-hand Actions panel. - Give the task a name and description, and click
Next
.
- In the Task Scheduler, click
- Set the trigger:
- In the Triggers tab, click
New
. - Select
Daily
and set the start time to the desired time you want the email to be sent. - Click
OK
.
- In the Triggers tab, click
- Set the action:
- In the Actions tab, click
New
. - Select
Start a program
. - In the Program/script field, enter the path to the Outlook executable (e.g.,
C:\Program Files\Microsoft Office\Office16\OUTLOOK.EXE
). - In the Add arguments field, enter the following:
/Automation /C "SendEmail"
(without quotes). - Click
OK
.
- In the Actions tab, click
- Save the task:
- Click
Finish
to save the task.
- Click
How it works
When the scheduled task runs, it will launch Outlook in automation mode and execute the SendEmail
subroutine, which will send the email using the VBA script. The email will be sent at the specified time.
Note: Make sure to adjust the Outlook executable path and the VBA script code to match your specific Outlook version and configuration.