Copy Excel Code to a Different Workbook

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.

  1. Open both workbooks
  2. On your keyboard, hold the Alt key, and press the F11 key, to open the Visual Basic Editor
  3. In the Project Explorer window, find both workbooks.
  4. In the workbook with the code, click the + sign to view the list of Modules
  5. Click on the module that you want to copy, and drag it over the project where you'd like the copy placed.
  6. 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.


You may also like...

5 Responses

  1. I created a little tool for this purpose some time ago:

  2. Thanks Jan Karel, that’s good to know.

  3. Primo says:

    Does anyone else find it completely odd that it’s only drag-and-drop that works? Whenever i want to do this, I always try copy-paste, Ctrl-C Ctrl-V, before I remember that it doesn’t work.

  4. Dan Elgaard says:

    After watching the video, something struck me: How do one make these videos???

    Do you setup a video camera in front of the screen, and film it, or does some sort of software exists that will “film” what’s going on, on the screen???

  5. Primo, it is odd that copy and paste doesn’t work, just the drag and drop.

    Dan, I use Camtasia from TechSmith to record and edit the onscreen videos. They also have free software, Jing, that you can download here:

Leave a Reply

Your email address will not be published. Required fields are marked *