Open In App

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

Last Updated: 06 Dec, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

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

Output:

Output

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?

Answer:

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?

Answer:

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?

Answer:

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

Q4: How to Edit a Macro after Creating it?

Answer:

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?

Answer:

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.



News
Improve
Discuss
Do you want to advertise with us?Click here to know more

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

article_img
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 RibbonFollow 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]. Step 2. Select a Macro from the list (e.g. updateText) and Press “Run” Output: How to Run Macro from VBA EditorFollow 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] Step 3. Select anywhere in the macro code and click the “Run button” (Green Arrow) or Press F5 How
Read More

N

How to Create a Macro in Excel: Build, Run, and Use Macros Easily

article_img
How Do I Create a Macro in Excel- Quick StepsOpen MS Excel > Start Recording a MacroPerform the Actions You Want to Automate > Stop RecordingRun the MacroAre repetitive tasks consuming your time in Excel? With this Excel macros tutorial, you can learn how to create and use macros in Excel to automate tasks and improve efficiency. This guide will walk you through the essentials, from understanding what macros are to creating a macro button for quick access. Whether you're a beginner looking for a step-by-step guide to Excel macros or someone eager to explore advanced features, this article provides everything you need to make and run a macro with ease.How to Create a Macro in ExcelTable of ContentWhat is Macro in Excel Uses of Macros in ExcelHow to Create a Macro in ExcelHow to Run a Macro in ExcelHow to Create a Macro button in ExcelEasy Tips for Creating a Macro What is Macro in Excel An Excel Macros is a set of instructions that you can create to automate repetitive tasks. Think of it like a recorded script that performs actions such as formatting cells, entering data, or generating reports, all with just a single click. This helps save time and reduces the chance of errors
Read More

How to Run a Macro Automatically

article_img
To run a macro automatically when the workbook opens one must enable the developer's tools in Microsoft Excel. What is a Macro in Excel Macros allows automating repetitive tasks in Microsoft Excel. Some tasks need to be performed multiple times and repetition of all the actions would consume time. In such type of Scenarios, Macros helps in automating these tasks. How to Enable the Developer's ToolStep 1: Go to File > Options > Customize Ribbon Step 2: Then checkmark the Developer's tool option in the customize ribbon option. Now you can record Macro, run Macro and do everything that a developer can do. How to Run Macro Automatically when the workbook opensStep 1: Go to the developer's menu and then go to the visual basic Step 2: Go to ThisWorkbook Tab Step 3: Write down Private Sub Workbook_open() and hit enter. You will then see the below screen. You can write your code or basically whatever you want between this and it will automatically run every time the workbook is opened. Let us make a Welcome Message Box: Step 4: Save the workbook as Excel Macro-Enabled Workbook. Note: If you don't save it as an Excel macro-enabled workbook then it will not save the macros and it will
Read More

Excel Personal Macro Workbook

article_img
When we create the macros for automation, they can be used for that particular workbook only. We cannot access them outside that workbook in others. Excel Personal Macro Workbook is a hidden workbook in your local system that pops up whenever you open the Excel application. It is a place where all the macros from any workbook can be stored and one can use the macros from here which are often required. How to create a personal macro workbook? Creating a personal macro workbook is similar to creating a macro in Excel. Let's discuss it in some simple steps : Click on the developer tab on the ribbon and then click on the Record Macro tool in the Code group.A new dialog box would open.In the option, "Store Macro In", choose Personal Macro Workbook. In this way, our macro would be stored in the personal macro workbook.After filling the dialog box, click OK.In the last, click on stop recording in the developer tab. This is how a personal macro workbook can be created. How to view, create, copy and edit macros in Personal Macro Workbook? All the options like view, create, copy and edit macros can be done from VBA(Visual Basic for Applications) Editor. Let's discuss it in some simple ste
Read More

How to Password Protect Your Excel Macro?

article_img
It is a best practice, to protect the Macro (VBA Code) from other users to edit or view. In this article, we explain to create a simple macro and protect the same "VBA Project" using a password in Excel from other users. Implementation: Follow the below steps to protect your excel macro with a password: Step 1: Open an excel file, to create a simple “hello world” macro. Step 2: Press Alt + F11 – to open Visual Basic Editor. Step 3: Click Insert >> Module, which will add a new module as in Img1. Img 1 Step 4: Type the below code in “code window”. Sub firstMacro() MsgBox "Hello World" End Sub Step 5: Right-click “VBAProject (Book1)” and then click “VBAProject Properties”. Step 6: GoTo Protection Tab >> Check “Lock project for viewing” and type your password in both Password and Confirm password input text boxes. Press “OK” Step 7: Save your Excel workbook as Excel Macro-Enabled Workbook (*.xlsm) and close Step 8: Now reopen your excel file. Press Alt+F8 – to open the Macro dialog box. Select the macro “firstMacro” and click “RUN”. Step 9: Our macro will pop up below the message box. Close or press OK to hide the message box Step 10: Press Alt + F11 – to open Visual Bas
Read More

How to Record a Macro in Excel

article_img
Excel Macro is simply a record button that records a set of actions performed on Excel that can be run multiple times. For example, if you have to format some raw data on a weekly basis you can use a macro to record yourself formatting the data once and let Excel automate the task in the future. it's used to help users save time and avoid performing redundant tasks. What is a Macro in ExcelIn simple words, a Macro is a snippet of VBA code that empowers you to execute a series of actions with a single command. Whether you're generating this code using a macro recorder or crafting it manually, it all falls under the umbrella of macros. How to Get the Excel Developer Tab Show Up in the RibbonThe first step to record a macro is to get the Developer tab turned on. If you already see the Developer tab in the ribbon, then you can directly follow the steps to record a macro. How to Enable the Developer Tab in ExcelIn order to record a macro the Developer tab on the ribbon needs to be activated as it isn't on by default within Microsoft Excel. The developer tab contains all the macro tools among various other features. How to Activate: To activate it click on the file tab> go to options
Read More

Assigning Excel Macro to Objects

article_img
In Excel, a recorded macro can be assigned to different objects like a shape, graphic, or control note. Instead of running the macro from the required tool in ribbon, we can create these objects to run them easily. They get very handy when multiple macros are there. Individual objects can be created for different macros. In this article, let's discuss how can we assign macros to different objects : 1. Assigning Macro to a Shape It is one of the easiest ways to run a macro is to create any shape in the worksheet and use it for running the macro. The steps that need to be followed are: Click on the Insert Tab on the ribbon. Go to the Illustrations group and click on the Shapes icon. In the sheet, choose any shape we like and want it to be assigned as the macro. Click where you want to add the shape in the sheet and the shape will automatically get inserted. The shape can be resized or re-formatted accordingly to the way you want. Text can also be added in the shape. Then Right-Click on the shape and a dialog box would be opened. Then click on Assign Macro. After right-clicking on the shape, another dialog box of Macro would be opened. In the dialog box, select the macro from the lis
Read More

What Does the Number in the Addchart2 VBA Macro represent?

A chart or graph can be made in an Excel spreadsheet by using the AddChart2 VBA macro. The desired chart type or style is indicated by the number in the AddChart2 VBA macro. The AddChart2 function uses this number as an input parameter to identify the type of chart or style to be constructed. Each chart type is given a different number. If change the argument 2 value, an area chart is represented by the number 1, a line chart by the number 3, and a pie chart by the number 5, similarly, formatting of charts can also be done if change the argument 1 value, data labels are added on the chart, by the number 202, dashed formatted chart is developed by the number 203. You can design a chart that displays your data in the most useful way for your purposes by providing the correct chart type. Data types Before moving forward, we need to learn about the various numerical data types, such as integers, decimals, or floating-point numbers, that may be part of the macro. The numbers in Addchart2 can be of any of the below-mentioned data types, hence it is necessary to know about them. 1. Integer: Using this data format, entire values can be represented between -32,768 and 32,767. 2. Long: Th
Read More

C

How to Enable and Use Power View in Excel?

Power View is a sophisticated visualization feature in Microsoft Excel that enables users to generate graphs, charts, and reports. It makes it easy for organizations to produce reports and dashboards that can be shared on a daily, weekly, and monthly basis with stakeholders, managers, and other team members. Power View Excel is regarded as one of the greatest offline reporting tools, and it performs well when paired with Excel Formulae, Pivot Tables, and other functionalities that make data analysis a breeze. It includes analytical tools for doing statistical forecasts and forecasting. How to Enable Power View with Microsoft Excel? In this part, you will learn how to enable Power View in Microsoft Excel. To begin, activate the Power View feature in Microsoft Excel settings. Step 1: Navigate to the File menu, choose More, and then click on Options. Step 2: A new window called Excel Choices will appear, displaying numerous options. Click on the Add-ins tab to see all of the possible add-in options. Step 3: Within Add-ins, there is a Manage: option, which offers a dropdown menu with all of the Excel add-ins. Select COM Add-ins from the Manage: menu and press the Go button. Step
Read More

How to Enable Macros in Excel (2025): Step-by-Step Guide

article_img
How to Activate Macros in Excel - Quick StepsOpen WorkbookClick Enable Content in the yellow security warning bar.Adjust Macro Settings (Optional):Go to File > Options > Trust Center > Trust Center Settings > Macro Settings.Choose the desired macro setting (e.g., Enable All Macros for trusted files).Save the file .xlsm to retain macros.Macros are an essential feature that helps automate repetitive tasks, making your workflow faster and more efficient. However, since macros involve executing scripts, Excel disables them by default for security reasons. This article provides a simple, step-by-step guide on how to enable macros in Excel, whether you need them for a single session or want to allow them permanently. If you’ve been looking for ways to streamline your tasks while ensuring data security, this guide is for you.Table of ContentWhat Are Macros in Excel and Why Are They Disabled by DefaultStep-by-Step Guide to Enable Macros in ExcelHow to Enable Macros in Excel on MacHow to Change Macro Security Settings in ExcelSecurity Best Practices for Enabling MacrosCommon Issues and TroubleshootingHow to Enable Macros in ExcelWhat Are Macros in Excel and Why Are They Disabled
Read More
three90RightbarBannerImg