[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Automate opening a spreadsheet and running a macro

Posted on 2011-05-03
Medium Priority
Last Modified: 2012-05-11
I would like to schedule a task the automatically opens a spreasheet and runs a macro every day. Is this posible and if soi how?
Question by:MarkRichardStanley
  • 4
  • 2
LVL 37

Expert Comment

ID: 35513579
Yes. It's easy. Just add a macro that runs on Workbook_Open and make a .bat file that just calls the spreadsheet. Then add that .bat file to a task in Task Manager.

Expert Comment

ID: 35513587
LVL 37

Expert Comment

ID: 35513609
Now, you'll have to fix the macro security to allow the macro to run without prompting. If you made the macro on the machine, it should run as a trusted macro otherwise I suggest using digital signatures instead of using the lowest macro security setting (which would work).
Details here: http://office.microsoft.com/en-us/excel-help/digitally-sign-a-macro-project-HA001231781.aspx
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 37

Expert Comment

ID: 35513612
Yes, sorry. I meant Task Schedular not Task Manager.

Author Comment

ID: 35514137
Why would I need to use a BAT file and not just call the actual spreadsheet? Also, according to Microsoft it is better to use VB Code. http://office.microsoft.com/en-us/excel-help/running-a-macro-when-excel-starts-HA001034628.aspx

What do you think?
LVL 37

Accepted Solution

TommySzalapski earned 1000 total points
ID: 35514250
Actually you should use Workbook_Open not Auto_Open. Auto_Open only runs when the workbook is opened automatically.

Why would I need to use a BAT file and not just call the actual spreadsheet?
You can't point task schedular to open a worksheet (at least you couldn't last time I tried). Just make a text file and put the path of the Excel sheet in the file and save it as a .bat. It's super easy.

Also, according to Microsoft it is better to use VB Code
Right, you use VB code to run the macro when the Excel file opens, but you need Task Scheduler to tell it to open once per day or else you'll need to leave the excel sheet sitting open all day. Also with Task Scheduler, you can set it to run the task at a certain time, but also to run as soon as possible if it happens to be off at that time for some reason.

You could use a vbscript file instead of a .bat file and put VB code to open the sheet and run the macro but the .bat file is much simpler.

Author Closing Comment

ID: 35514317
I was able to use the Task Scheduler to open the actual excel file directly.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question