Last updated: October 14, 2010 0:33 AM
Search Contextures Sites ![]()
Excel VBA -- Adding Code to a Workbook
Copy Excel VBA Code to a Regular Module
Copy Excel VBA Code to a Worksheet Module
Copy Excel VBA Code to a Workbook Module
Copy Excel VBA Code From a Different Workbook
Copy Excel VBA Code to a Regular Module
You may find Excel VBA code in a newsgroup message, or on a web site, and decide to add it to one of your workbooks. Most Excel VBA code can be added by doing the following:
- Copy the Excel VBA code that you want to use
- Select the workbook in which you want to store the Excel VBA code
- Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
- Choose Insert | Module
- Where the cursor is flashing, choose Edit | Paste
To run the Excel VBA code:
- Choose Tools | Macro | Macros
- Select a macro in the list, and click the Run button
Watch the Video
View the steps described above, in a short video clip.
Copy Excel VBA Code From a Different Workbook
You may find Excel VBA code in a sample workbook online, and decide to add it to one of your workbooks. You can copy all the code in a module by doing the following:
- Open both workbooks
- Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
- In the Project Explorer, find your workbook, and the workbook with the code that you want to copy. The screenshot at the right, the code is in VBACodeCopy.xls and will be copied to MyForm.xlsm
- In the workbook with the code, click the + sign to view the list of Modules
- Click on the module that you want to copy, and drag it over the project where you'd like the copy placed.
- Release the mouse button, and a copy of the module will appear in the workbook.
To run the code:
- Choose Tools | Macro | Macros
- Select a macro in the list, and click the Run button
Watch the Video
View the steps described above, in a short video clip.
Related Excel VBA Tutorials
- FAQs, Excel VBA, Excel Macros
- Create an Excel UserForm Video
- UserForm with ComboBoxes
- Excel VBA Edit Your Recorded Macro
- Excel VBA Getting Started
Contextures Inc., Copyright ©2012
All rights reserved.