Four Ways to Run A Macro in Excel (2024)

In our previous blog, we had learned to create a macro by recording it. In this blog, we would learn multiple ways to run a macro in excel. There are four ways that you can use to run and execute a macro in Excel.

Before this, you need to have a macro ready in your workbook. You can create a macro by either recording a new macro or by writing a VBA code in Visual Basic Editor (VB Editor).

Table of Contents

  1. Methods To Run A Macro in Excel
  2. Run Macro Dialog Box in Excel
  3. Using VBA Editor Window
  4. Run Macro By Clicking on the Shape
  5. Running Macro Using A Click Button

Firstly, let us for this blog, write a small VB code that enters the text ‘Excel Unlocked’ in the cell A1. To do this, follow the under mentioned steps.

Press Alt+F11 on your keyboard to open the VB Editor window.

Right-click on the Sheet1, then select the option ‘Insert’ and click ‘Module’.

Four Ways to Run A Macro in Excel (1)

The excel would insert a new module named ‘Module 1’ and the code window.

Four Ways to Run A Macro in Excel (2)

Now, copy the below VBA code (This VBA code would insert the text ‘Excel Unlocked’ in cell A1) and then paste it in the ‘Code Window’.

Also Read: How to Automatically Run a Macro when Workbook is Opened?

Sub RunMacro()

ActiveSheet.Range(“A1”).Value = “Excel Unlocked”

End Sub

Here in the first line of this code, the string ‘RunMacro’ represents the name of the Macro.

Now Close the VB Editor Window by clicking on the “X” button on its top-right corner.

Methods To Run A Macro in Excel

There are basically four methods that you can use to run a macro in Excel. These are:

  1. Using the ‘Run Macro’ Dialog Box
  2. VB Editor Window
  3. By Assigning Macro to Shape
  4. By Assigning Macro to Button

Let us now learn each of these methods one by one.

Run Macro Dialog Box in Excel

This is the basic method to run a macro in Excel. In order to run a macro using this method, you need to first activate and enable the ‘Developer’ tab in Excel. Please go through our previous blog on ‘Start Automation – Record a Macro in Excel’ where you would learn how to activate the ‘Developer’ tab in Excel.

It looks like this:

Four Ways to Run A Macro in Excel (4)

Now, when you have this tab in your workbook, follow the below steps to run the macro.

Under the ‘Code’ group of the tab ‘Developer’, click on the button ‘Macros’.

Four Ways to Run A Macro in Excel (5)

In the ‘Macro’ dialog box that appears on your screen, you would find the name of your macro ‘RunMacro’. Just select this and click on the button ‘Run’ as shown in the screenshot below:

Four Ways to Run A Macro in Excel (6)

As a result, you would notice that the excel executes the code behind this macro and writes the word ‘Excel Unlocked’ in cell A1.

Four Ways to Run A Macro in Excel (7)

Using VBA Editor Window

Another method to run a macro in excel is by using the run button on the VBA editor window. Follow the below steps to achieve the same.

Also Read: Start Automation – Record A Macro in Excel

Again, we need to have the ‘Developer’ tab enabled on our screen.

Under the ‘Developer’ tab option, click on the button named ‘Visual Basic’ as highlighted in the screenshot below:

Four Ways to Run A Macro in Excel (8)

The ‘VB Editor’ window will appear on your screen with ‘Module 1’ as a selected node and your code would also be visible over there.

Four Ways to Run A Macro in Excel (9)

Just above the code window, you would notice the ‘Run Sub/UserForm’ button as highlighted in the screenshot below:

Four Ways to Run A Macro in Excel (10)

Click on this button or use the keyboard shortcut F5 (need to click on Run button), and you would notice that the code executes and writes the word ‘Excel Unlocked’ in the cell A1.

Four Ways to Run A Macro in Excel (11)

Run Macro By Clicking on the Shape

We can even insert a shape in the worksheet and just by clicking on this shape, we can execute the macro code.

Follow the below steps:

Insert the shape of your choice using ‘Insert’ Tab > ‘Illustration’ Group > Click on the ‘Shapes’ button and click on the shapes of your choice.

Four Ways to Run A Macro in Excel (12)

Click and drag on the part of the worksheet where you want to insert the selected shape.

Now right-click on the inserted shape and click the option ‘Assign Macro’.

Four Ways to Run A Macro in Excel (13)

The ‘Assign Macro’ dialog box would appear on your screen. You would notice that your macro is available in the list. Select it (RunMacro) and click on OK.

The macro now is assigned to the shape.

Four Ways to Run A Macro in Excel (14)

Now take your cursor on the shape, and you would see that the mouse pointer changes its shape to a hand-like symbol.

Four Ways to Run A Macro in Excel (15)

Now, click on the shape and you would see that the macro gets executed and inserts the word ‘Excel Unlocked’ in cell A1.

Four Ways to Run A Macro in Excel (16)
Four Ways to Run A Macro in Excel (17)

Running Macro Using A Click Button

This method works in a similar way as the above method. Instead of inserting the shape, we would use the button to execute the macro.

The difference between a button and a shape is that you can format a shape, but you cannot format the button. However, you can edit the button text.

Follow the below steps:

Firstly, we need to insert a button. For that, we need to have the Developer tab enabled/activated.

Then, go to the ‘Developer’ Tab > ‘Control’ group > ‘Insert’ Option > Click on the ‘Button’ option as highlighted in the screenshot below:

Four Ways to Run A Macro in Excel (18)

As a result, the mouse pointer would change to a plus symbol. Click on the location where you want to insert the button.

As soon as you click, the ‘Assign Macro’ dialog box would appear on your screen. Select the macro name (RunMacro) and click on the ‘OK’ button.

As a result, the excel inserts the button (with default name as ‘Button 1’). You can change the name by right-clicking on the border of the button and select the option ‘Edit Text’.

Four Ways to Run A Macro in Excel (19)

Once you change the name of your button, press the ‘Escape’ (Esc) button on your keyboard to deselect the button.

Now, take your mouse cursor on the button and you would notice that the excel changes the mouse cursor to a hand-like symbol.

Four Ways to Run A Macro in Excel (20)

Finally, click on this button and you would notice that the excel executes the macro and inserts the text ‘Excel Unlocked’ in cell A1 (based on the VBA Code).

By this, we have complete with all the methods using which you can run a macro in Excel.

Share your views and comments in the comment section below.

RELATED POSTS

  • 19 Everyday Use Excel VBA Codes
  • Edit Macro – Rename, Shortcut key, Copy
  • Write a Macro using VBA Editor – Command Button
  • Worksheet Events in VBA Excel
  • Personal Macro Workbook VBA- Create and Use
  • Where to Put VBA code?
Four Ways to Run A Macro in Excel (2024)

FAQs

Four Ways to Run A Macro in Excel? ›

We can record a macro in Excel or write from scratch in VB Editor. Excel provides different options to run a macro. In this article, we explore four different approaches to running a macro in an Excel application.

How many methods are there to run a macro in Excel? ›

We can record a macro in Excel or write from scratch in VB Editor. Excel provides different options to run a macro. In this article, we explore four different approaches to running a macro in an Excel application.

How do you run macros in Excel? ›

Run a macro from the Developer tab
  1. Open the workbook that contains the macro.
  2. On the Developer tab, in the Code group, click Macros.
  3. In the Macro name box, click the macro that you want to run, and press the Run button.
  4. You also have other choices: Options - Add a shortcut key, or a macro description.

What is Excel 4 macro? ›

Excel 4.0 macros, aka XLM macros, were first added to Excel in 1992. They allowed users to add commands into spreadsheet cells that were then executed to perform a task. Unfortunately, we soon learned that (like any code) macros could be made to perform malicious tasks.

What are the ways to write a macro in Excel? ›

How To Create A Macro In Excel
  1. Make the 'Developer' tab visible. The 'Developer' tab is a special tab in Excel that helps users access additional features and tools, like creating macros. ...
  2. Record the macro. To create a macro, click on the 'Developer' tab on your ribbon. ...
  3. Provide macro details. ...
  4. Perform the desired actions.
Aug 8, 2023

What are all the types of macro? ›

There are three types of macronutrients: carbohydrates, proteins, and fats.

What are macro commands in Excel? ›

A macro is an action or a set of actions that you can run as many times as you want. When you create a macro, you are recording your mouse clicks and keystrokes. After you create a macro, you can edit it to make minor changes to the way it works.

How to run macros every time Excel starts? ›

Click Developer > Record Macro. In the Macro name box, type Auto_Open. In the Store macro in box, pick Personal Macro Workbook. This will make the macro available every time you open Excel.

How do I run a macro on a schedule in Excel? ›

Using the top menu, click "Action" and then "Create Task". You only need to give it a name here - any will do. If you wanted it Weekly/Monthly you simply select the circles in the top left. Set the start time around 10 minutes from your current time.

How do I enable macros in Excel? ›

How to enable macros in Excel permanently
  1. Open your Excel file. Click on your Excel application to open the correct file with the macro. ...
  2. Find the Trust Center. ...
  3. Navigate to "Macro Settings." ...
  4. Enable all macros. ...
  5. Learn how to disable macros for the future. ...
  6. Consider a quicker way.
Sep 27, 2023

Where is macros Excel? ›

Here's how you can find macros and VBA modules in your document: In Word or Excel, click View > Macro > View Macros. In PowerPoint, click View > Macro.

What is the macro key for Excel? ›

In the Developer tab, click Macros to view macros associated to a workbook. Or press Alt+ F8. This opens the Macro dialog box.

What are the basics of macros? ›

What Is a Macro? Macros refers to a set of programs or instructions enabled to automate a repetitive task. It includes recording, naming, saving, and executing in Visual Basic for Applications or VBA as per the requirement. The feature can be played as many times as required and is beneficial in saving time and effort.

How to do macros? ›

How to count macros
  1. Step 1: Determine your daily calorie requirement. Your body doesn't just burn calories when you're exercising. “ ...
  2. Step 2: Factor in your weight goal. ...
  3. Step 3: Figure out your ideal macronutrient ratio. ...
  4. Step 4: Plug those values into a macronutrient calculator. ...
  5. Step 5: Start tracking macros.
Jan 7, 2021

What is macro and its steps? ›

A macro records operations and re-uses the sequence of mouse actions or keystrokes of anything you can do in Excel with keystrokes or a mouse. Some of those actions include; cleaning up data, formatting cells, creating tables or organizing data in an Excel spreadsheet.

What is the maximum macros in Excel? ›

Excel apparently has a limit on VBA code such that you cannot have more than 64K of compiled code in a single procedure. The solution to this problem is to chop up your long macro into shorter procedures. For instance, you might divide your monster macro into, say, a dozen smaller macros.

In which ways can a macro be created? ›

You can create macro using programming tools such as Visual Basic for Applications (VBA) in Microsoft Office applications like Excel and Word. You can also use external software to create macros for other applications or use built-in macro features in some software.

How many ways are there to stop a macro? ›

If the Macro is simply in a continuous loop or is running for too long you can use one of these keyboard shortcuts to kill it: Esc hit the Escape key. Ctrl + Break hit Ctrl key and then the break key, which is also the pause key.

Top Articles
Latest Posts
Article information

Author: Stevie Stamm

Last Updated:

Views: 5824

Rating: 5 / 5 (80 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Stevie Stamm

Birthday: 1996-06-22

Address: Apt. 419 4200 Sipes Estate, East Delmerview, WY 05617

Phone: +342332224300

Job: Future Advertising Analyst

Hobby: Leather crafting, Puzzles, Leather crafting, scrapbook, Urban exploration, Cabaret, Skateboarding

Introduction: My name is Stevie Stamm, I am a colorful, sparkling, splendid, vast, open, hilarious, tender person who loves writing and wants to share my knowledge and understanding with you.