Table of Contents (VBA Code in Excel)
- #1 – How to Paste VBA Codes in Module?
- #2 – How to Save the VBA Code in Excel?
- #3 – How to Assign Macro Code to Shapes?
VBA or also known as Visual Basic Applications is a programming language for excel and not only excel for most of the Microsoft office programs we use VBA, in Excel VBA can be found under the developer tab as it is meant for developers, to access the developer’s tab we need to enable it first and then we can access it from the tab or by the keyboard shortcut ALT + F11.
Excel VBA Code
If are new to VBA and you have no idea then this article is for you. In this article, we will show you how to copy the VBA code, where to paste the code, and how to run it in your module in Excel. Read on…
Enable Developer Tab in Excel
To use VBA Code in excel first thing is you need to do is make sure the developer tab is visible on your excel ribbon.
If your excel is not showing Developer tab then follow below steps to enable the developer tab in your excel.
Step 1: Go to File.
Step 2: Click on Options.
Step 3: Go to Customize Ribbon.
Step 4: Check the Developer tab on the right side. Once you select the options click on OK.
#1 – How to Paste VBA Codes in Module?
If you are searching for the VBA code and you got it, the first thing you need to do is go to Developer tab and click on Visual Basic.
You can also press the excel shortcut key “ALT + F11” to open the Visual Basic.
As you open the visual basic you will see a window like the below.
Go to Insert and click on Module.
As soon as you click on the module it will be inserted and you can see the Module name and also you will see a white plain board on the right.
In the white plain board, you need to paste your copied VBA code.
After pasting the code, you need to execute it.
We can conduct the execution process in two ways one is by pressing the shortcut key F5 or else by clicking the green run button on the top.
The copied VBA code will be executed in your window.
#2 – How to Save the VBA Code in Excel?
I know you don’t need any special introduction to save the excel file, but when it comes to VBA code contained excel workbook you need one special introduction.
If the Excel workbook is already saved and you just copied VBA code then you need to change the file extension because when you click on save option you will see below alert message.
This says the workbook you are trying to save contains VB project, cannot be saved as normal excel workbook. You need to save this workbook as “Macro-Enabled” workbook.
Click on Save As or press F12 key to save as you will see below a window.
Enter the file name as per your wish but select the Save as type “Excel Macro-Enabled Workbook (*.xlsm)
Click on OK to save the workbook as Macro-Enabled Workbook.
#3 – How to Assign Macro Code to Shapes?
Whenever we need the VBA code to be run we need to go back to the visual basic editor and run, this is a time-consuming process.
We can assign a macro by its name to one of the shapes. Follow the below steps to assign the macro to shapes.
Step 1: Go to Insert and Select the shape as per your wish.
Step 2: After selecting the shape to draw this on your worksheet. Ideally away from the data.
Step 3: Right click and select Edit Text.
Step 4: Add the word as per your wish. I have added the word as “Click Here to Run the Macro”.
Step 5: Again right click and select the option to assign a macro.
Step 6: Now we will see all the macro list. Select the macro name you wish to assign.
Step 7: Click on OK. Now, this button holds the macro code. Whenever you click on this button this code will be executed.
This has been a guide to VBA Code in Excel. Here we learn how to Copy, Insert & Run the VBA Code in Excel along with simple and practical examples. Below are some useful excel articles related to VBA –