How to Automatically Email an Excel Attachment Every Two Hours
Question details
The user needs to automate the process of sending a specific Excel workbook as an email attachment at recurring two-hour intervals.
- Product
- Microsoft Excel 2019
- Device & OS
- Windows
- Scenario
- Automating recurring email distribution for continuous data reporting or team sharing without manual intervention.
- Observed behavior
- The user wants to achieve an automated state where a script combined with a system scheduler dispatches emails containing the Excel workbook every two hours.
Ensure you have Microsoft Outlook installed and configured with your email account on the computer, as the VBA script uses the Outlook application to send messages. Additionally, your Excel file must be saved as a Macro-Enabled Workbook (.xlsm).
Automate Email Sending using Excel VBA and Windows Task Scheduler
Combine a custom Excel VBA script to handle the email generation with Windows Task Scheduler to trigger the entire process automatically every two hours.
This approach requires creating a VBA macro that interacts with Outlook to create and send the email with the current workbook attached. After configuring the script to run when the workbook opens, you will set up Windows Task Scheduler to launch the file at the required intervals.
Open your Excel workbook, press ALT + F11 to launch the VBA Editor, and go to Insert > Module. Paste your email script utilizing the CreateObject("Outlook.Application") method to define the recipient, subject, and add the workbook path as an attachment using .Attachments.Add.
In the VBA Editor, double-click on 'ThisWorkbook' in the Project Explorer panel. Select 'Workbook' from the left dropdown and 'Open' from the right dropdown. Insert a command to call your email macro (e.g., Call SendEmail) so it executes automatically whenever the file is launched.
Navigate to File > Save As, choose your desired folder, and select 'Excel Macro-Enabled Workbook (*.xlsm)' from the format dropdown menu to ensure your code is preserved and executable.
Open the Start menu, search for 'Task Scheduler', and click 'Create Basic Task' in the right-hand Actions pane. Name your task and select 'Daily' for the initial trigger.
Double-click your newly created task to open its Properties, go to the Triggers tab, and click Edit. Check the box for 'Repeat task every', type '2 hours', and set the duration to 'Indefinitely'.
Go to the Actions tab, click New, and select 'Start a program'. Browse to select the EXCEL.EXE application path, and in the 'Add arguments' box, input the full file path to your saved .xlsm workbook in quotation marks.
Automate Your Workflow with WPS Spreadsheets
WPS Office provides a highly capable Spreadsheets application with robust VBA support. You can seamlessly write, edit, and execute macros to automate recurring tasks like email distribution through Outlook, completely free of charge.
- 1. Open Your Data in WPS: Launch WPS Office and open the spreadsheet you wish to automate.
- 2. Access the Developer Tools: Navigate to the Developer tab on the ribbon and click on 'Visual Basic' to open the built-in VBA code editor.
- 3. Insert the Outlook Automation Script: Go to Insert > Module, and paste your standard Outlook email automation script just as you would in Microsoft Excel.
- 4. Save and Schedule: Save the document as an .xlsm file and use the Windows Task Scheduler to automate its opening at your preferred intervals.

Frequently Asked Questions
Do I need to keep my computer turned on for the scheduled task to run?
Yes. Windows Task Scheduler requires the computer to be powered on to execute the Excel application and send the email. Unless you configure the task to run whether the user is logged on or not (with stored credentials), you must also remain logged in.
Can I use an email client other than Outlook for this macro?
The specific CreateObject("Outlook.Application") method only works with Microsoft Outlook. If you want to use a different client or connect directly to an SMTP server, you will need to rewrite the VBA script using CDO (Collaboration Data Objects).
Why does my macro stop and wait for me to click 'Allow' before sending?
This is a security feature in Microsoft Outlook designed to prevent malicious scripts from sending spam. To fix this, you can ensure your antivirus software is updated and recognized by Windows, which often disables the prompt, or adjust the Programmatic Access settings in Outlook's Trust Center.
How do I stop the automated emails from sending every two hours?
To halt the automation, open the Windows Task Scheduler, find the task you created in the Task Scheduler Library, right-click it, and select 'Disable' to pause it temporarily or 'Delete' to remove it permanently.




