Last week one of my clients asked for a bit of help, so I sent a workbook with some sample code to tackle the problem. It was just what he needed, so my client wanted to copy the code from the sample file, into his own workbook. Unfortunately, he wasn’t sure how to do that, and asked for a bit more help.
A quick way to copy code is to drag a module from one workbook to another, in the Visual Basic Editor. In this example, the code is in VBACodeCopy.xls and will be copied to MyForm.xlsm.
- Open both workbooks
- On your keyboard, hold the Alt key, and press the F11 key, to open the Visual Basic Editor
- In the Project Explorer window, find both workbooks.
- 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. It will automatically create a Modules folder, if necessary.
Copy and Paste Excel Code
If you only want some of the code on a module sheet, or to copy code from a worksheet or workbook module, you can copy and paste the Excel code.
Watch the Video
To see the steps for copying an entire module, you can watch the following short video.