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.
Find workbooks in Project Explorer window
Find workbooks in Project Explorer window

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 this short video.

________________

0 thoughts on “Copy Excel Code to a Different Workbook”

  1. 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.

  2. 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???

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.