Search TeachExcel.com
TeachExcel.com
TE
Teach Excel MS Office Tutorials Excel Consulting Services Excel Forum
Excel Video Tutorials Excel Tips Free Excel Macros Excel Help Resources Contact TeachExcel
Video Tutorials
  • Free Macros
  • Excel Help Directory
  • Excel 2007 Resources
  • Keyboard Shortcuts
  • Excel Forum
  • Contact/About

Excel Tips and Tutorials: Macros and VBA in Excel

Install a Macro into an Excel Spreadsheet

Bookmark and Share

This tip will show you how to copy an Excel Macro into your workbook or spreadsheet. You will learn the different locations that you might install the macro as well as what you need to make sure is included in the macro for it to work.

First - Every macro must start and end like the example below:

Sub The_Name_of_The_Macro()

The code for the macro goes here.

End Sub

Every macro in Excel must start with "Sub" and end with "End Sub." The name of the macro must have an open and closed parenthesis right after it. You can name the macro anything that you want but you should make it describe the function of the macro. All of the actuall code for the macro comes after the name of the macro and before "End Sub."

Second - There are a number of different places where you can install a macro in Excel and you need to know this before you install the macro. You can install a macro ino a Module, Worksheet, or Workbook - See Image Below.

Where to install the Macro

 

How to install the Macro into Excel - Steps

  1. Copy the code for the macro. Make sure to include the everything between the "Sub" and "End Sub."
  2. Opend the desired Excel workbook.
  3. Hit "Alt + F11" on the keyboard (this shortcut works for all versions of Excel).
  4. Determine where you need to install the macro.
  5. Double-click the location where you need to install the macro - it will look like the above image. So, double-click Sheet1 if you need to install the macro there, double-click ThisWorkbook if you need to instal the macro there. If you need to install the macro into a module, go to step 6, otherwise skip to step 7.
  6. If you need to install the macro in a module and don't already have a module visible, go to the Insert menu > then click Module. A module will then be added.
  7. Once a blank window has opened up you are ready to install the macro. If no window opened up, go back to step 5.
  8. Past all of the macro code into the blank window.
  9. Rename the macro if need be and then hit the keyboard shortcut "Alt + F11" to close the VBA window and go back to the spreadsheet.
  10. You are now ready to run the macro. Hit "Alt + F8" on the keyboard in order to view all macros in the workbook and also to run the macro.

This is what the macro should look like once installed:

VBA Window Macro in Excel




Bookmark and Share
Random Tutorials
Extract Text from Cells - Intermediate Example
(Intermediate)
Introduction to Making Formulas in Excel
(Easy)
IF Statement Introduction & Using Nested IF's
(Easy)
Function and Formulas Lookup in Excel
(Easy)
Formatting Worksheets for Printing in Excel
(Easy)
How to 'Protect' a Worksheet and Workbook
(Easy)
Contact | Privacy Policy | Disclaimer
Copyright© 2012 TeachExcel.com