+ Reply to Thread
Results 1 to 6 of 6

copy button with VBA code to another workbook

  1. #1
    Registered User
    Join Date
    06-15-2013
    Location
    Israel
    MS-Off Ver
    Excel 2016
    Posts
    38

    copy button with VBA code to another workbook

    Hi to all,
    I have five buttons with VBA code in an Excel sheet. I want to copy these buttons with their code to another workbook.
    The code has name range for each button.

    When I use copy and paste to the new sheet in a different workbook, the macro refers to the original sheet and not the current sheet. Is ther a way to copy the code for each button?

    In other words:
    How to copy " command button" from one sheet to another sheet - including the code?

    Khalil

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: copy button with VBA code to another workbook

    The buttons would need to be ActiveX buttons with click event code.
    You would need to Move/Copy the worksheet in order for buttons and code to be copied to a new workbook.

    If you have Forms buttons then you will need to manually copy the code into the new workbook AND change the Assign Macro reference for the button.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Valued Forum Contributor
    Join Date
    08-31-2007
    Location
    SW Ireland
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2311 Build 16.0.17029.20068) 32-bit
    Posts
    523

    Re: copy button with VBA code to another workbook

    Has a button a parent property i.e the name of the sheet it's located on? If so, I'm reckon that it's possible to do what is required if the button code refers to the parent sheet when updating the data.
    Excel 365 user. To unblock a downloaded macro-enabled workbook, go to your "Downloads" folder > right click on the workbook name > click 'Properties' > check the 'Unblock' checkbox. You can now open the workbook.

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: copy button with VBA code to another workbook

    Hi there,

    Take a look at the attached workbook and see if it gets you moving in the right direction. It uses the following code:

    Please Login or Register  to view this content.
    The highlighted values may be altered to suit your requirements.

    Please note that a Reference to "Microsoft Visual Basic for Applications Extensibility 5.3" must be set in the VBA Editor.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    06-15-2013
    Location
    Israel
    MS-Off Ver
    Excel 2016
    Posts
    38

    Re: copy button with VBA code to another workbook

    Hi,
    Thank you all.
    Have it done
    Thank

  6. #6
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: copy button with VBA code to another workbook

    Hi again,

    Many thanks for your feedback - glad it's working for you now.

    Regards,

    Greg M

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 01-31-2016, 05:54 AM
  2. Replies: 12
    Last Post: 07-29-2014, 01:06 PM
  3. how to copy workbook (book1) to workbook (boook2) with the help of command button
    By shivam432 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-05-2014, 08:09 AM
  4. Replies: 0
    Last Post: 07-24-2013, 01:09 PM
  5. VBA Code for button to copy results from formula into another workbook
    By ghost_soul in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-08-2013, 01:02 PM
  6. [SOLVED] VBA Code to Save Copy File without Macro Button and VBA Code on Copy?
    By cychua in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 10-12-2012, 07:23 AM
  7. Copy sheet and command button along with code to new workbook
    By sglavan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-30-2012, 10:18 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1