Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving macro'ed button from one sheet to another

Status
Not open for further replies.

MCubitt

Programmer
Mar 14, 2002
1,081
GB
If I want to move a button which has many macros behind it, from one worksheet to another (in same work book) how may I do this?

Using tradiitonal Copy (or cut) and Paste loses the macro behind it.

thanks


Applications Support
UK
 
Don't know about Excel, but in Word, while you can copy the button control itself, as you have discovered, the code does NOT come along with it. This is a function of SCOPE. Code in form modules (as opposed to standard or class modules) are PRIVATE to that form module - as long as the other form module is in the same project...which it is.

You can export the form module to another project, rename it and import it back into the first project.

Gerry
 
Well, The not so pretty way would be to copy the button over. Then, launch the VB editor and copy all of the code from one sheet to the destination sheet. You might have to tweak the Userform so it sees the code in the new sheet but it should work.

The other method would be to place the code in a module instead of the Sheet. That would allow you to call it from any sheet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top