


This is just one example - Use your imagination and let me know what you come up with!įor more VBA tips, techniques, and tactics, subscribe to our VBA Insiders email series using the form below.Īfter you subscribe, share what you’re automating on Twitter and Facebook. You can even do it directly from Outlook, if you wanted. With this method, you can print all your sheets to a PDF in the background, without waiting for Excel to load. It’s also a waste of time to open your Excel workbook just to print the sheets to a PDF. Why reinvent the wheel to convert it to VBScript?įor example, if you already have an Excel Macro to print all your worksheets to a PDF, there’s no point rewriting it to work with VBScript. It’s in these moments where it’s beneficial to create a VBScript file to run your existing macros from outside Excel. There are many instances where you could copy your Excel Macro to a VBScript file and run it directly, but sometimes you don’t want to deal with that headache. It also pulls information from a database and reports how many new sales I made yesterday.Įach morning, I’ll execute this VBScript code directly from Microsoft Outlook to get a quick snapshot of how my business is performing without having to wait for Excel to load! Do you want to try the same? Check out my tutorial on how to run applications from your Outlook Ribbon. The macro I referenced in my example calculates the total return on sales for the current month. Now, all you have to do to run your macro is double click ReportSales.vbs! Once you’ve modified the Application.Run statement, save your file and close it. The path shown in the Open statement should match the file path shown in your Run statement. Set book = (" C:\Users\Ryan\Desktop\Sales.xlsm",TRUE) To open a read-only workbook, try adding the following line right before your line: If you want to save your workbook after running your macro, add a new line and type in your VBScript, right before the line that reads. Keep in mind, if your file name or file path has spaces, you’ll need to surround the path with double quotes. "' C:\Users\Ryan\Documents\WorkbookName.xlsm'! Sheet1. macro name"įor instance, if you had an Excel macro under Sheet1 of your workbook stored in My Documents, your Application.Run line would look something like: "' full path to excel file'! module name. The Application.Run line looks for the 3 inputs described below: "' C:\Users\Ryan\Desktop\Sales.xlsm'! SalesModule. To run your own Excel macros, there’s only one line you’ll need to edit: Open the file and paste the example macro into the file.The important part is the file should have a. Create a file anywhere on your computer and name it ReportSales.vbs.


Are you ready to learn how to customize this to run your own Excel macros? Initial File Setup
