How To Run Vba Code In Excel Automatically

UIAutomation”) p. Any file you place in this folder will open automatically when you start Excel. Open a Excel and in a worksheet cell A2 enter the formula =IF(A1>5,myMacro,"") 2. The following VBA code example clears the color in all the cells on the worksheet by setting the ColorIndex property equal to 0, and then highlights the entire row and column that contain the active cell by using the EntireRow and EntireColumn properties. Create a Workbook_Open() sub within ‘ThisWorkbook’. However, deleting them may be time consuming in large workbooks if you're trying to find and delete every single image manually. Application. In this workspace, you can create, test, and run any code that you assign to components in your application. Select For v = 1 To s. You have some neat macros that you want to run automatically whenever you or anyone else opens your presentation or when PowerPoint starts up. Events are actions performed by users which trigger Excel VBA to execute code or by actions of other VBA code. This streamlines the launching of Excel and makes sure that no unnecessary code is running during automation. Automatically enable macros in Excel. Copy the above code and Paste in the code window. Sub sbVBS_To_SAVE_ActiveWorkbook() ActiveWorkbook. Can someone please let me know how this is possible. Right-click the sheet tab that you want to use, and then choose View Code from the context menu, 2. bas file which does the work I want to do in Excel. Force users to enable macros in a workbook Sometimes it is important to make sure that macros are enabled for your workbook. Today let's look at a couple of ways to get an Excel Macro to run automatically when you open an Excel workbook. For example, you may want to have one file of all your receipts with date, account, category, provider, product/service, and cost entered one line at a time, as they occur—an instance of evolving accounting rather than static accounting. However, there are a substantial number of differences in how Excel itself behaves between the two platforms, and in how VBA interacts with these platforms. VBA Express : Excel - Trigger a macro when a formula result changes. Using the PDFTables API, you can use VBA to convert PDF to Excel. Run an Excel Macro With a Worksheet Button In my workbooks, I sometimes add buttons to run macros. Suppose if you want to open new excel file, the file name is in A1 ,for that we can write the code in Macro and Run the macro then the file will open. You do not need to be a programmer or a very technical person to enjoy the benefits of macros in Excel. This macro code will help you to automatically add serial numbers in your Excel sheet. The code below, however, accepts an argument and stores the same in the workbook Function Store_Value(ByVal sPPTName As String) Sheet1. Visible = True Application. Code is below. Macro Monday time again folks. Let us show you how to make Excel delete all pictures automatically using VBA. How to Automatically Run Macro When an Excel Workbook is Opened Run VBA Code on Protected. Open the workbook to test it, it will Run a Macro Automatically. A message box with. Let's face is: creating VBA macros is real programming. It also checks to. You could write some VBA code to tell Excel to grab the current stock quote of only the stocks that have been checked, emailing certain people if the stock rises or drops at set points. learn to customize the Excel environment by altering the toolbars, menus and keyboard shortcuts to suit their needs. Entering and editing text in a VBA module works as you might expect. Any code that has the capability of modifying the VBA excel codebase has the capability of introducing nasty code into your workbook. In the Professional Version , Total Access Emailer offers a VBA programmatic interface that lets you run these email blasts from your MS Access code. If you want to distribute your workbook with VBA code written for Solver, you should write the code using the earliest expected version of Excel, so it will work on all versions that users may have installed. It also has the ability to automatically open a designated form when the database launches. Like this using VBA coding, we can automate the process of creating a pivot table. Learn How to Use Excel Macros to Automate Tedious Tasks Jason Faulkner Updated July 5, 2017, 5:43pm EDT One of the more powerful, but seldom used functions of Excel is the ability to very easily create automated tasks and custom logic within macros. If you get a lot of emails and you need to analyse the data in them, then importing your emails from Outlook into Excel with VBA will save you a lot of time. You will not have to worry about adding this to all your new code because once this is checked off it will be automatically applied to any new module you add to the VBA editor. Applies to: The information in this topic applies to document-level projects for Excel and Word. Copy the above code and Paste in the code window. Sub procedures are capable of doing a week's worth of work in Microsoft Excel in mere seconds. The best workaround you could do is connecting the VBA code with a workbook open event so that it runs and maybe closes the file afterwards. Specifies that the filename that Excel uses is "Excel VBA Close Workbook". Macros are sometimes made into Addins or Addins may be programmed in another language such as C++, but we'll skip over addins. Events can be suppressed, if not required. How to Automate Mail Merge through VBA in Microsoft Excel. Hi Friends, in this article i will explain about How to open another excel file using Macro in Excel 2007. In this tutorial you'll quickly learn the correct syntax to create a VBA message box (also referred to as a pop-up dialogue box) in Excel. For business use, you can create complete powerful programs powered by excel and VBA. Press Alt+F11 to open VBA Editor. Select Run a Script as the Action and select the RunRules macro. Available from Juno Download. Visible = True ThisWorkbook. Make sure there is just enough data to demonstrate your need. / VBA to Create PDF from Excel When you run the macro the VBA code does the following : I have created an excel file that automatically saves the excel file. But I've been running into problems lately using the macro you helped create for me. Here's a simple subroutine that exports an Access table to Excel using VBA code. The following numbers are corresponding to the picture on the right. This article teaches you. This enables the programmer to create vba code that is executed automatically at the time of an event. The only way to have macros enabled on a system is for a user to manually choose the options via the Excel Options menu. And if you want to follow along, here is a blank file to follow along. Once you write the code in the VBA Editor, you can run it and let the code work its magic on your spreadsheet. Sometimes, the best route for entering code for Excel 2016 is the most direct one. It's free to sign up and bid on jobs. Click Here Before Posting Data or VBA Code ---> How To Post Data or Code. This macro code will help you to automatically add serial numbers in your Excel sheet. The following basics will help you get started. This tutorial walks you through the VBA code to refresh the PivotTable automatically. Writing VBA code in Excel has many challenges. Automatically Run Macro when Cell Changes Posted on November 11, 2010 by andrew walker in Excel 2003 Help , Excel 2007 Help , Excel 2010 Help , Excel VBA , Macros with 36 Comments Sometimes it is necessary to have a macro run when the contents of a specific cell changes. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Learn How to Use Excel Macros to Automate Tedious Tasks Jason Faulkner Updated July 5, 2017, 5:43pm EDT One of the more powerful, but seldom used functions of Excel is the ability to very easily create automated tasks and custom logic within macros. Once created, you need to run the macro. Automating PowerPivot Refresh operation from VBA. Hello, I am fairly new to VBA in Excel. Application. Solver is a powerful analysis tool, bundled with Excel and used for optimization and simulation of business and engineering models. When you store numbers inside of variables, one of the things you can do with them is mathematical calculations. VBComponents("Module1"). VBA code can be defined as the code that inputs in the visual basic window to perform a set of instructions or actions in excel and provide results. Excel PivotTables do not refresh automatically when data is updated. When I reset the code, it runs fine. Automatically Run Excel Macros When a Cell Changes. It's important to note that the two macros DO NOT run at the same time. It also has the ability to automatically open a designated form when the database launches. Scheduling Excel to Run a Procedure at periodic intervals or at a specific time of day, with the OnTime Method. AutoSignin Set s = p. To trigger VBA events when you open Excel; This isn't just something interesting you can do with Excel, it's actually a useful technique to save time and control the Excel environment. Specifies that the filename that Excel uses is “Excel VBA Close Workbook”. The availability of macros is very helpful for the users as they can create user defined programs and functions specifically designed to perform their tasks. To run VBA code, you have to access the VBA editor firstly, which can be achieved by the following 2 means: In Outlook, under the "Developer" tab, click on the "Visual Basic" button. Presented below is a brief introduction on how to type and run a VBA Sub procedure in Excel VBA. Now we all are good to go. The VBA reference is set from "References" in the VBA editor's Tools menu. Recommended Articles. Excel indirect columns from another sheet for row dragdown Vba - why is excel closing when running this code for copy/paste data into multiple sheets? How to put a VBA code inside command button of excel sheet using VB. " - Leonardo da Vinci Welcome to part one of the Ultimate VBA Tutorial. This code will save the Active Workbook which we have currently activated. Click Insert, Module. Export your VBA code for use in another Excel application. Excel VBA (Visual Basic for Applications) is the name of the programming language of Excel. Debugging VBA Code. Now, in this article, we will teach you to run VBA code in Excel step by step. If you want to autorun a macro when opening a worksheet then you need to type your macro name in the Worksheet_Activate() event and this code will run a macro when opening your Excel. You start recording, do your steps and stop recording. Now we all are good to go. where my only source is a excel file that i. Macros allow non-programmers to automate repetitive tasks in Excel. I cannot get this to automatically run when the cell values are changed. How to run Excel file with VBA Macro in android cellphone? I have Sasmung Galaxy S3 and I have created a word generator in Excel. Sub procedures form the backbone of the programs written to command Microsoft Excel. The following VBA code is to Save the Excel File. The advantage of this approach is you can leverage the powerful features of excel in your own custom programs. Save End Sub Instructions to run the VBA code to save Active Excel Workbook Please follow the below steps to execute the VBA code to save the excel file. How to duplicate sheets in Excel with VBA. But if you want to open it when Outlook is closed with VBA it is not so difficult if you use Early Binding but not as easy if you use Late Binding in order for your code to run on different versions without issues. It helps track changes to Excel files and gives a clear picture of who, how and when modified the document. The only new item is the Filename parameter (#4). Trigger a macro when a formula result changes Runs a macro when a value changes as the result of a change elsewhere on the sheet or in the workbook. Here is an example of how to run another macro from a macro using the Call Statement. This tiny article describes how you can use the Windows SDK function ShellExecute to start any program or shortcut (. The VBA interoperability project is a joint Novell & Sun incubator project whose aim is to deliver a way to run Excel and Word macros natively in imported documents. One way to work around this issue is to build a certain backdoor in our code. Re: Auto run macro when open worksheet You may disable macros in Excel security so they will not run automatically but rather ask for permission. In fact, most of the Excel worksheet functions can be accessed and used in VBA code. Events are actions performed by users which trigger Excel VBA to execute code or by actions of other VBA code. You have some neat macros that you want to run automatically whenever you or anyone else opens your presentation or when PowerPoint starts up. Specifies that the filename that Excel uses is “Excel VBA Close Workbook”. In some circumstances, it may not be desirable to disable all event handling as your application may rely on various events to run properly. Create the rules you want to run but do not enable them to run automatically. You will notice the same records are there in the excel sheet. Basically if we have 1000 mins available work time each day and we have to build 100 units per day then our takt time would be 10 mins. It is easy to make workbooks automatically. The best workaround you could do is connecting the VBA code with a workbook open event so that it runs and maybe closes the file afterwards. Sub procedures are capable of doing a week's worth of work in Microsoft Excel in mere seconds. We can then add our UserForm1. Create a Workbook_Open() sub within ‘ThisWorkbook’. Go to tab "Developer" and click on "Macro" button. Save End Sub Instructions to run the VBA code to save Active Excel Workbook Please follow the below steps to execute the VBA code to save the excel file. Open the Excel 2010 spreadsheet that holds your VBA code. Run in Excel. find what the code is doing and correct mistakes. Re: Auto run macro when open worksheet You may disable macros in Excel security so they will not run automatically but rather ask for permission. Do you need to run a macro when Excel starts? You have two options: 1. Macro and VBA. The Create a Macro chapter illustrates how to run code by clicking on a command button. Just like you can password protect workbooks and worksheets, you can password protect a macro in Excel from being viewed (and executed). " In my case, this statement is only partially true. Run method of Excel VBA to execute a particular macro. These buttons are used to execute your code, pause the code's execution, and stop the code from running. a worthy goal. It can assist you to accomplish a lot of tasks not supported by the native features in Excel. Or if you have Outlook running, you can adapt the code found here to automatically open and run an Excel macro: Handling Multiple Inboxes For example, if you set up a task reminder in Outlook to trigger at the time you want, you can set up an event handler in Outlook to open the Excel workbook and run the appropriate macro at that time. Today let’s look at a couple of ways to get an Excel Macro to run automatically when you open an Excel workbook. Place a Auto_Open() sub within any module. To do that, open a blank Excel workbook, then go to File >> Options >> Trust Center >> Trust Center Settings >> Macro Settings , or press Alt+T+M+S respectively. Simply create a subroutine called Auto_Close and place code in it, or call another sub from there. In VBA programming, a function returns a value. OnTime function should be just fine. The answer is simple - first create your macro, then add a single line of VBA code to About this tutorial: Video duration: 4:15 How to auto-run a VBA project when an Excel workbook is opened. If you are interested to run a custom code when the slide changes during the slideshow, then here is a VBA script snippet that you can modify to run your own code. I tried pasting the code directly into "ThisOutlookSession" but that did not seem to achieve the desired result. In your case, we want to open the form when the "Workbook_Open" event fires. The Create a Macro chapter illustrates how to run code by clicking on a command button. Did you know that the Select method has an optional parameter? Check Excel VBA help and you will find the syntax is. How to send an instant message from excel using communicator. You may have the need to run some code periodically and automatically, such as code to pull data from an external data store. Solver and Conventional VBA. Before we can write any code, we need to know the basics first. You cannot unfreeze the scrolling once it's run the code while opening the file. When I reset the code, it runs fine. Let us show you how to make Excel delete all pictures automatically using VBA. For example extraction of first name, middle name, and the last name is the common scenarios we have seen. In this workspace, you can create, test, and run any code that you assign to components in your application. How to Enable Macros in Excel Macros can be defined as a set of instructions that can be used to perform some specific tasks in Microsoft Office applications. When you enter information into a workbook, Excel automatically recalculates every Calculate Next Set wks = Nothing End Sub I want to make a micros vba excel project how it is possible. Excel's forum. Summary: Above VBA Excel code placed in the post "Adding VBA code lines automatically" placed in website "exceldb. Now, we have finished creating the VBA Code, we can run our code to create a pivot table. If you get a lot of emails and you need to analyse the data in them, then importing your emails from Outlook into Excel with VBA will save you a lot of time. However, deleting them may be time consuming in large workbooks if you're trying to find and delete every single image manually. Instructions: Open an excel workbook. VBA code won't run, even with Macro Security set to Enable All Macors I've developed an Excel 2007 (Windows 7) sheet with a VBA front end In order for this to. I will start out by showing how a change to a single cell can trigger an action. Press Alt+F11 to open VBA Editor. The VBA interoperability project is a joint Novell & Sun incubator project whose aim is to deliver a way to run Excel and Word macros natively in imported documents. Basically what we are going to do is to use the OnSlideShowPageChange() event at the presentation level to detect when the slide is changed during a slideshow in PowerPoint 2010, but you can also use this snippet in PowerPoint 2007. The next two macros are examples of what I call "automatic code," because they execute automatically, if a certain condition is met. VBA can, however, control one application from another using OLE Automation. Excel VBA Read a Text File with VBA, and Write the Text to Excel. I tried pasting the code directly into "ThisOutlookSession" but that did not seem to achieve the desired result. The following sample demonstrates inserting a code module into Microsoft Excel, but you can use the same technique for Word and PowerPoint because both incorporate the same VBA engine. As a beginner to Excel VBA, you might find it difficult to decide where to put your VBA code. Before we can write any code, we need to know the basics first. It is a programming language that Excel uses to record your steps as you perform routine tasks. Excel, just like other Office products, supports inserting pictures of various formats into your workbooks. This has been a guide to Excel VBA MsgBox. Excel Experts, VBA Tips, Enable Events In VBA you can use events to capture certain things that happen on a workbook If you use Events in your spreadsheet system, it is important to understand that they are fired off by default when VBA code is run. This action opens a Visual Basic for Applications workspace. As far as Sharepoint Foundation is concerned, I don't believe you can do this, but on your server you CAN initiate the macro which should include (or in a. email attachments from any unread email in my inbox and saves the attachment to a folder on my hard drive. In other words, you type the code by using your keyboard. Close VBA to close All Workbooks. XLAM loaded however. Today let's look at a couple of ways to get an Excel Macro to run automatically when you open an Excel workbook. For purposes of this guide, there is no essential difference. Press Alt + F11 to open Visual Basic Editor (VBE). Change chart data range using a Drop Down List [VBA] Filter an Excel defined Table based on selected cell [VBA] Populate a combobox with values from a pivot table [VBA] Add values to a regular drop-down list programmatically [VBA] Filter an Excel defined Table programmatically [VBA] Populate a list box with unique distinct values from a. Simply create a subroutine called Auto_Close and place code in it, or call another sub from there. Using Loops to Repeat Code Why You Need Loops The macro recording tools in Microsoft Word and Microsoft Excel make easy work of creating simple coding tasks, but running a recorded macro is just that – you do a job once. Is there a way to programmatically do this in VBA? The code is below. In fact, it should work on any computer that has later versions of Excel and Solver. Do you need to run a macro when Excel starts? You have two options: 1. When you store numbers inside of variables, one of the things you can do with them is mathematical calculations. During the process of creating VBA programs a lot of junk code builds up in your files. In the Professional Version , Total Access Emailer offers a VBA programmatic interface that lets you run these email blasts from your MS Access code. Just like you can password protect workbooks and worksheets, you can password protect a macro in Excel from being viewed (and executed). Hi Friends, in this article i will explain about How to open another excel file using Macro in Excel 2007. Make sure that the code is in the ThisWorkbook scope of the VBA editor and not in a module or worksheet: Option Explicit Private Sub Workbook_Open() MsgBox "Autorun works!" 'your code here End Sub And make sure that your macros are enabled. Learn more about AutoMacro - A VBA. If you’re interested in learning VBA the easy way, check out my Online Excel VBA Training. VBA can use, but not create, ActiveX/COM DLLs, and later versions add support for class modules. Value = "This is secret code". Excel, has the ability to automatically execute or run an Excel macro code. The advantage of this approach is you can leverage the powerful features of excel in your own custom programs. Before we can write any code, we need to know the basics first. The sample uses a static text file for the code module that is inserted into Excel. Automatically open Excel Workbooks in Folder and Run VBA Code Posted on September 28, 2010 by andrew walker in Excel 2003 Help , Excel VBA , Macros with 2 Comments If you have multiple Excel workbooks that have to have the same process completed in each it can become quite laborious to complete the task manually. If you choose to use both then Workbook__open will run before Auto_open. Currently I'll change the cell Color Fill within a cell in column A and run the macro to display the hexadecimal code in the same cell as the color. For example, maybe you open a time sheet file every day to keep track of your hours as you work on projects. Did you know that the Select method has an optional parameter? Check Excel VBA help and you will find the syntax is. In order for automatically-running subroutines to work correctly in Microsoft Excel, they must be contained within a Visual Basic module. It can assist you to accomplish a lot of tasks not supported by the native features in Excel. You can select. Learn How to Use Excel Macros to Automate Tedious Tasks Jason Faulkner Updated July 5, 2017, 5:43pm EDT One of the more powerful, but seldom used functions of Excel is the ability to very easily create automated tasks and custom logic within macros. Create Pivot Cache. You can execute Function procedures and call the function in Excel 2016. It will update itself, not minding how large or small our source data is. Run the Solver Using a VBA Macro. Go back to Excel. I previously had program running with much success for over two years on a windows 7 machine, however I recently upgraded to windows 10 pro and latest version of excel with VBA 7. Once you write the code in the VBA Editor, you can run it and let the code work its magic on your spreadsheet. In Excel 2003 it looks like this:. The idea is that the user only need enter the zip code and the application uses it to lookup the state and city information automatically. Let us show you how to make Excel delete all pictures automatically using VBA. This post explains how you can automatically install and activate an Excel Addin using VBA code. By default, exporting Access report as Excel gives you no formatting but plain text. The row where the execution halts will be highlighted yellow. Which is “kind of ok”, if the VBA code only works on German computers. Run the Solver Using a VBA Macro. To run the macro, press the key F5, and data will get filtered and we can see the data as per the clicks which is more than 5000 and less than 10000. VBA Express : Excel - Trigger a macro when a formula result changes. That's where you store the sheet event code for that sheet, and only for that sheet. Entering and editing text in a VBA module works as you might expect. Automatically enable macros in Excel. find what the code is doing and correct mistakes. This enables the programmer to create vba code that is executed automatically at the time of an event. This will take us to the VBA window where we can enter our VBA code. Right-click on your workbook name in the "Project-VBAProject" pane (at the top left corner of the editor window) and select Insert -> Module from the context menu. Excel VBA makes it a cinch to automate the entire process. Similarly, entering data into a cell or saving a Workbook are also Excel events. Application. For your reference, I have given code below. We will then identify the key pieces of code to change. You simply carry out the specific task that you would like to automate and the macro recorder will convert that into Excel VBA code. Excel VBA separate line break data into different rows Excel VBA unmerge columns automatically For some systems, when you export a non-Excel report (e. So I ran into the issue of having to run some Excel macros automatically from the Windows command line (cmd). Right-click the sheet tab that you want to use, and then choose View Code from the context menu, 2. Type or paste the code in the newly created module. Back when I worked as a full-time Excel consultant, I occasionally was hired to make sense out of VBA code written by accountants who had left the department. Figure 7 – Define data range. The monitoring of the application starts as soon as the workbook is opened, which occurs it does so in the background. I require some VBA code which will run a countdown timer in a cell in an excel sheet. Windows("Immediate"). net" could be copied from other website. Why would you want. Open a Excel and in a worksheet cell A2 enter the formula =IF(A1>5,myMacro,"") 2. This will open the VBA Editor and display the Sheet Code Module for that sheet. The following code works opening a workbook. You can access the settings from a different spreadsheet. Run Access Macro using RunCode. Did you know that the Select method has an optional parameter? Check Excel VBA help and you will find the syntax is. Let's face is: creating VBA macros is real programming. Type or paste the code in the newly created module. How to Automatically Run Macro When an Excel Workbook is Opened Run VBA Code on Protected. Or you can directly press “Alt + F11” key buttons. How to Create and Use Personal Macro Workbook in Excel. Like this using VBA coding, we can automate the process of creating a pivot table. email attachments from any unread email in my inbox and saves the attachment to a folder on my hard drive. When we click on RUN, we will be instantly presented with the Pivot Table field, here, we will select " More Tables ", then Yes; Figure 14 - Select Worksheet. Visual Basic for Applications, or VBA for short, is the scripting language used in Microsoft Office to automate tasks in applications such as Microsoft Excel. Hi all I have the following code and would like to run this automatically whenever I open the workbook. To trigger VBA events when you open Excel; This isn't just something interesting you can do with Excel, it's actually a useful technique to save time and control the Excel environment. Sub procedures form the backbone of the programs written to command Microsoft Excel. There is a free addin AutoEvents that enables PowerPoint to run macros automatically on certain events. The only new item is the Filename parameter (#4). Press [Alt] [F11]. VBA message box is extremely useful when you are debugging; You have an option to insert VBA MsgBox anywhere in your code; VBA MsgBox will help you out when you want to ask the user a query. Just add a line to your macro to use it. You will not have to worry about adding this to all your new code because once this is checked off it will be automatically applied to any new module you add to the VBA editor. Here's an introduction to these functions. You can record and run macros with either Excel commands or from Excel VBA. How do I auto-size comment box to fit its content with VBA Macro code in Excel. Excel's forum. …The simplest case is to run a macro by double. Excel, the 22nd installment in their joint series of digital spreadsheet magic tricks, you'll learn how to use VBA code for conditional formatting as well as how to do it using the OFFSET, MOD and ROWS functions. You can follow the. Working with Cells and Ranges in Excel VBA. dll) allows you to right-click, left-click and change your cursor position. Excel for Beginners -by Kristoff deCunha. A useful practice when setting up a new Excel workbook is to reserve one. VBA can, however, control one application from another using OLE Automation. So you don't need to do anything active like clicking a button or the like to run the code. With some simple VBA code, you can call upon the the Application's OnTime method to automatically run a procedure. Run VBA from VBscript. The macro can then be run in the normal way from the Tools menu or from a custom button or menu item. 23 things you should know about VLOOKUP When you want to pull information from a table, the Excel VLOOKUP function is a great solution. Macros allow non-programmers to automate repetitive tasks in Excel. This code will save the Active Workbook which we have currently activated. We will start with a simple Excel Table on Sheet2. How to Loop Through Worksheets in a Workbook in Excel VBA? Using the For Each Loop The code below loops through all worksheets in the workbook, and activates each worksheet. We will see an example of how to construct an array with elements identified only at run time. In Excel, you can create a macro by recording it or by writing a code in the VB editor. Before running the code you need to change some setting. Simply create a subroutine called Auto_Close and place code in it, or call another sub from there. Automating PowerPivot Refresh operation from VBA. Copy Excel VBA Code to a Worksheet Module Another type of Excel code is Event code, which runs automatically when something specific occurs in the workbook. We will add the following code to our macro to name the new sheet using user input: This above code creates a variable to store the user name we receive from the Input box. Visual Basic for Applications VBA basics. RE: VBA Macro Excel run macro Automatically? Hi there what code do i place in the this worksheet part to make the macro for excel run when the document is opened ?. Learn How to Use Excel Macros to Automate Tedious Tasks Jason Faulkner Updated July 5, 2017, 5:43pm EDT One of the more powerful, but seldom used functions of Excel is the ability to very easily create automated tasks and custom logic within macros.