Open In App
Related Articles

How to Enable & Run a Macro in Excel? 6 Ways

Improve Article
Save Article
Like Article

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.

Even while executing an Excel macro is a straightforward process for seasoned users, it might not be clear to newbies. You will discover numerous ways to execute macros in this article, some of which may entirely alter the way you interact with Excel files.

The below macro will write the text “Geeks for Geeks” in cell B5

Sub updateText()

ActiveSheet.Range(“B5”).Value = “Geeks for Geeks”

End Sub

How to Run a Macro from Excel Ribbon

Follow the below steps to run a macro in the Macro dialogue box:

Step 1. Go to View >> Macros >> View Macros – to pop-up Macro dialogue box [keyboard shortcut – Alt+F8].

View Tab

Step 2. Select a Macro from the list (e.g. updateText) and Press “Run”

Macro dialogue box



How to Run Macro from VBA Editor

Follow the below steps to run a macro in VBE:

Step 1. Open Excel

Step 2. Go to Developer>> Visual Basic – to open VBA Editor [keyboard shortcut – Alt+F11]

Opening VBA Editor

Step 3. Select anywhere in the macro code and click the “Run button” (Green Arrow) or Press F5

VBA Editor

How to Run a Macro with Custom Keyboard Shortcut in Excel

Follow the below steps to assign a keyboard shortcut to execute a Macro:

Step 1. Go to View >> Macros >> View Macros – to pop-up Macro dialogue box [keyboard shortcut – Alt+F8]

Step 2. Select Macro from the list (e.g. updateText) and Press “Options”, to pop-up Macro Options

Macro Dialogue Box

Step 3. Give any specific text in shortcut key input [e.g. Ctrl+p] and Press “OK”. Close Macro list

Macro Options  Dialogue Box

Step 4. Just press your Shortcut key, e.g. Ctrl+p, to execute the macro.

How to Create a Macro Button in Excel

Follow the below steps to add a shape in Excel to execute a macro:

Step 1. Click Insert in the Controls group of the Developer tab, then choose Button under From Controls. Add a button, “Run Macro”

Create a Macro Button

Create a Macro Button

Macro button

Step 2. Right-click Shape and Press “Assign Macro”, to pop up the Assign Macro dialogue box

Assign Macro to button

Step 3. Select “updateText” Macro and Press “OK”

Assign Macro dialogue box

Step 4. Just click the shape “Run Macro” in your Excel file to run the macro

The macro can now be executed by clicking its button. The assigned macro formats the chosen cells as seen in the screenshot below.

Before Clicking the button


After Clicking the Button


How to Create a Macro Button from a Graphic Object

Unfortunately, button controls cannot have their appearance customized, which is why the button we just constructed does not look very beautiful. You can use shapes, icons, pictures, WordArt, and other things to create a really lovely Excel macro button.

Follow the below steps to create a Macro button from a Graphic Object:

Step 1. Select the Illustrations group, from the Insert Tab, Select Shapes, and choose the desired shape

Macro Button from a Graphic Object


Step 2. Click on your worksheet and then place the shape object there and create your shape button in the desired format

Step 3. Right-click the shape object, select Assign Macro from the context menu, then select the required macro and press OK to bind the macro to the shape

Assign Macro to the shape


Now you have a shape that resembles a button and when you click on it, it executes the designated macro.

Run the macro by clicking on the shape

Run the macro by clicking on the shape

How to Add a Macro Button to Quick Access Toolbar

The macro button added to a worksheet looks nice, but it takes time to add a button to every sheet. Add your preferred macro to the Quick Access Toolbar to make it accessible from anywhere.

Step 1. Use the context menu by right-clicking the Quick Access Toolbar and selecting More Commands

Customize Quick Access Toolbar


Step 2. Select Macros

Adding a Macro Button to Quick Access Toolbar


We can make a few more adjustments or click OK to save the changes

Step 4. If the icon added turns out to be unsuitable for your macro, click Modify to change it to a different icon

Modify the macro button

Step 5. Select a desired icon for your macro button from the Modify Button dialogue box

Step 6. Click on OK once done

Well Done! You now have a button on Excel that will start a macro.

Macro button on the Quick Access Toolbar

You just need to select the Excel macro execution method that best suits your requirements now that you are aware of the various available options. I appreciate your time and hope to see you on some of our other blogs.

FAQs on Macro in Excel

Q1: What is the main usage of macro?


A macro is an action or series of acts that can be repeated endlessly. You are capturing your keystrokes and mouse clicks when you construct a macro. You can edit a macro after you’ve created it to make a few tiny modifications to how it functions.

Q2: What methods can we use to run a macro?


Here are some ways to run a Macro in Excel

  • Run a Macro from Excel Ribbon
  • Run Macro from VBA Editor
  • Run a Macro with Custom Keyboard Shortcut
  • Create a macro button in Excel
  • Make a Macro Button from a Graphic Object
  • Add a Macro Button to Quick Access Toolbar

Q3: Can you run a macro without opening Excel?


Without first opening the file containing the macro, you cannot run an Excel VBA macro.

Q4: How to Edit a Macro after Creating it?


To edit a macro after creating it you first have to open the VBA editor by pressing “Alt +F11”, Find the macro in the project explorer window, make the changes you need and sav ethe workbook to update the macro.

Q5: Macros are safe to Run or not?


Macros can be harmful if they are created by an untrusted source or if they have malicious data. To protect your system, Excel prompts you to enable or disable macros when you open a workbook containing them. You should only enable macros from trusted sources or from workbooks you created on your own.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 06 Dec, 2023
Like Article
Save Article
Similar Reads
Complete Tutorials