Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel VBA Schedule Task: Automate with Windows Task Scheduler

· 7 min read · Home Automation

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

You can schedule an Excel VBA macro to run automatically by creating a Windows Task Scheduler task that opens the workbook and triggers the macro. The reliable method is to put a small Workbook_Open macro in the workbook that calls your main routine, then have Task Scheduler launch Excel with that file at the time you choose. This works on Windows desktops and servers; Mac Excel has no equivalent to Windows Task Scheduler, so scheduling is a Windows-only technique.

What You'll Need

  • A Windows PC or server where the task will run (Windows 10 or 11, or Windows Server).
  • Microsoft Excel installed on that machine, with the workbook saved as .xlsm (macro-enabled) or .xlsb.
  • Permission to create a task in Task Scheduler (standard users can create tasks for their own account; some options require an administrator).
  • The workbook stored in a local folder the task account can access, not on a removable drive or a synced cloud folder that may be offline.
  • Macro security settings that allow the workbook's macros to run, or the workbook placed in a Trusted Location.

Step-by-Step

  1. Write the macro you want to schedule. Open the workbook, press Alt+F11 to open the VBA editor, and put your routine in a standard module (Insert > Module). Give it a clear name, for example Sub RunScheduledReport(). Test it manually with F5 before scheduling anything.
  2. Add a Workbook_Open trigger. In the VBA editor, double-click ThisWorkbook in the Project Explorer. From the left dropdown choose Workbook and from the right dropdown choose Open. In the generated procedure, call your routine, for example Call RunScheduledReport. Save the workbook.
  3. Decide how Excel should close. If the macro should finish and close Excel, add Application.Quit at the end of your routine, or close the workbook with ThisWorkbook.Close SaveChanges:=False. If you leave Excel open, the next scheduled run may find a second instance already running, so closing is usually cleaner.
  4. Place the workbook in a stable folder. For example C:\Automation\Reports\DailyReport.xlsm. Avoid OneDrive or SharePoint paths that may not be available when the task runs, and avoid mapped network drives that may not be connected under a different user account.
  5. Trust the location. In Excel, open File > Options > Trust Center > Trust Center Settings > Trusted Locations and add the folder containing the workbook. This prevents the macro from being blocked by security prompts when the task runs unattended.
  6. Open Task Scheduler. Press the Windows key, type Task Scheduler, and open it. In the right-hand Actions pane, click Create Task (not Create Basic Task, so you can set the working folder and other options).
  7. Name the task and set the security options. On the General tab, give the task a descriptive name. Choose Run only when user is logged on if the macro needs the desktop session; choose Run whether user is logged on or not only if you have stored the account password and the macro does not depend on the interactive desktop. Tick Run with highest privileges only if the macro genuinely needs elevated rights.
  8. Create a trigger. Go to the Triggers tab, click New, and choose the schedule (Daily, Weekly, or Monthly) plus the start time. Set the task to repeat if needed. Make sure the trigger time is when the PC is on, or tick the option to run as soon as possible after a missed start.
  9. Create the action. Go to the Actions tab, click New, and set Action to Start a program. In Program/script, enter the full path to Excel, for example C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE (the exact folder varies by Office version and installation type). In Add arguments, enter the workbook path in quotes, for example "C:\Automation\Reports\DailyReport.xlsm". In Start in, enter the folder path without the file name, for example C:\Automation\Reports.
  10. Set conditions and settings. On the Conditions tab, clear Start the task only if the computer is on AC power if this is a laptop that may run on battery. On the Settings tab, tick Allow task to be run on demand and decide whether to stop the task if it runs longer than a set time.
  11. Save and test. Click OK, enter the account password if prompted, then right-click the task and choose Run. Watch Excel open, confirm the macro ran, and check that Excel closed if your macro was written to close it.
  12. Review the history. In Task Scheduler, select the task and open the History tab (or the Last Run Result column) to see whether it completed successfully. If the result is not what you expect, see Troubleshooting below.

Common Mistakes

  • Putting the macro in a worksheet module instead of a standard module or ThisWorkbook, so it never fires on open.
  • Forgetting the Workbook_Open call, so Task Scheduler opens Excel but nothing runs.
  • Leaving out quotes around the workbook path in the arguments field, which makes Excel open with an error or no file.
  • Pointing the task at a OneDrive, SharePoint, or disconnected network path that is unavailable to the task account.
  • Not adding the folder to Trusted Locations, so the macro is disabled by security settings.
  • Choosing Run whether user is logged on or not without realising the macro may need an interactive desktop, or without storing the password correctly.
  • Leaving Excel open after each run, so later runs open extra instances or hit a "file in use" prompt.

Tips

  • Keep the scheduled macro short and self-contained; avoid message boxes and input prompts, which will block an unattended run.
  • Log results to a text file or a sheet so you can confirm each run happened, since you will not be watching the screen.
  • Use a dedicated Windows account for scheduled jobs if the task must run without a logged-in user, and make sure that account can read the workbook folder.
  • Test the task with the Run command before relying on the trigger time.
  • If the workbook must stay open for other users, schedule a copy rather than the live file.

Troubleshooting

If the task does not run at all, first check the Last Run Result in Task Scheduler and the History tab. A result indicating the task could not start often means the Excel path in Program/script is wrong; browse to EXCEL.EXE to confirm it. If Excel opens but the macro does not run, check that macros are enabled for that folder and that Workbook_Open is in ThisWorkbook, not a sheet module.

If the task runs only when you are logged in, review the General tab: Run only when user is logged on is the usual cause. If the task fails with a file-not-found message, confirm the workbook path is local and that the Start in folder matches. If you see a prompt about enabling macros or a protected view warning, add the folder to Trusted Locations. If Excel stays open and later runs fail, add Application.Quit to the macro or close the workbook at the end.

If the task account cannot access the file, test by signing in as that account and opening the workbook manually. If you changed the macro or workbook, run the task manually once to confirm the new version works before waiting for the schedule.

Frequently Asked Questions

Can I schedule a macro without opening the workbook?

Not directly through Task Scheduler. The practical method is to have Task Scheduler open the workbook, and let a Workbook_Open macro call your routine. Some automation tools can drive Excel externally, but the built-in Windows scheduler works by launching a program.

Does this work on Mac Excel?

No. Windows Task Scheduler is a Windows feature. Mac users need a different scheduling tool, and the steps above apply to Windows only.

Why does the task open Excel but show a security warning?

Macro security or Protected View is blocking the file. Add the workbook folder to Trusted Locations in Excel's Trust Center settings, and make sure the file is saved as a macro-enabled format.

Can the task run when nobody is logged in?

Only if you choose Run whether user is logged on or not and store the account password. Be aware that macros relying on the interactive desktop may behave differently in that mode.

How do I stop Excel from staying open after the run?

End your macro with Application.Quit or close the workbook with ThisWorkbook.Close SaveChanges:=False. Test manually to confirm Excel exits cleanly.

What if the scheduled time is missed because the PC was off?

In the trigger settings, enable the option to run the task as soon as possible after a scheduled start is missed. The exact wording varies slightly by Windows version.