+ Reply to Thread
Results 1 to 16 of 16

Easy way to assign Macro button

  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Easy way to assign Macro button

    Hello:

    I have lots of sheets with monthly sheet.
    In each sheet a have assigned a Macro button to summary the monthly report and all the sheets have the same macro.
    Now i am changing the name of macro and this is causing me to reassign each macro button in each sheet to the new macro name.
    I wonder if there is easy way to assign the new macro to all sheets in one go.

    I could assign the name of the macro and its location on each sheet at certain same location if needed.

    Please let me know if you have any questions.
    Thanks.

    Riz

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Easy way to assign Macro button

    Hi, Riz,

    what kind of buttons: Forms (as I assume) or ActiveX? Why not change the contents of the macro to suit instead of attaching a new one?

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Easy way to assign Macro button

    Hi HaHoBe:

    This will be Forms and it is in my PERSONAL.XLSB


    Please let me know if you have any questions.
    Thanks.

    Riz

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Easy way to assign Macro button

    Hi, Riz,

    that answered one of my questions but not why you donīt alter the code inside your personal workbook to suit.

    Please Login or Register  to view this content.
    You would need to alter the name of the button (should be the same on every sheet) and the name of the new macro (maybe add the name of the module as well if there are multiple macros with the same name - a no go for me!).

    Ciao,
    Holger

  5. #5
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Easy way to assign Macro button

    Hello:

    May be its is misunderstood.
    I have Macro name called Macro1,Macro2, etc in Perosnal.xlsb file.

    i have assigned Macro1 to lots of sheet.
    Now I realize to rename the "Macro1" to "MonthlyReport" so that it makes more sense for future editing.
    So now i rename the "Macro1" to "MonthlyReport".
    Now for each button i have assigned "Macro1" in the excelbook, i have to go back t each sheet and reaasign the macro button to macro called "MonthlyReport".
    This is very time consuming and prone to error while assigning the correct Macro from list.

    I hope this is clear, if not please do not hesitate to ask any questions.

    Thanks

    Riz

  6. #6
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Easy way to assign Macro button

    Hi HahoBe:

    I see you have created VB Code for me to rename the macro.
    Couple of questions.
    This is what i have
    5 seperate file and each file has macro within it self.
    Now I am moving the macro in Personal.xlsb file so that it can be used universally.
    I am seeing your code :

    Const cstrBUTTON As String = "Button 1"

    Now the question i have is how to assign where "Button 1" is
    Lets say the name of the button is 2014-Store1_DailySales.xls'!Macro1" and it is in file "2014-Store1_DailySales.xls"


    Please let me know if you have any questions.
    Thanks.

    Riz

  7. #7
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Easy way to assign Macro button

    Hello haHoBe:

    I have used your code but for some reason nothing is happening, bascially it is not renaming.

    PLEASE HELP.

    Riz

  8. #8
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Easy way to assign Macro button

    Hello:

    Please see below the code i am using as per your :
    Please Login or Register  to view this content.

  9. #9
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Easy way to assign Macro button

    Hiu, Riz,

    I still doubt that all your buttons are named CDI_Mix_Paste but I will learn in a couple of more posts from you.
    Please Login or Register  to view this content.
    Ciao,
    Holger

  10. #10
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Easy way to assign Macro button

    Hello Hahobe:

    To simply please refer to attached sample workbook.
    There are four sheets in the book.
    All sheets have Button named X1 and is assigned to "RunSummary" macro.
    Now i have updated and created another macro called "RunSummary_New" and want to assigned all macro Button from each sheet to this new macro.
    I used your code to assign the macro on each sheet by our code and seems not to work.
    Please help and let me know if any q.

    Thanks

    Riz
    Attached Files Attached Files

  11. #11
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Easy way to assign Macro button

    Hi, Riz,

    code for the last attachment would look like
    Please Login or Register  to view this content.
    as well as the macro codes being called like
    Please Login or Register  to view this content.
    Ciao,
    Holger

  12. #12
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Easy way to assign Macro button

    Hi HahoBe:

    Please refer to the attached file.
    I have adopted exactly like you have mentioned but still not working.
    Please look at it and let me know what i am missing to complete the help.
    Would appreciate you can try and correct and upload working file.

    Thanks

    Riz
    Attached Files Attached Files

  13. #13
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Easy way to assign Macro button

    Hi, Riz,

    right-click the button and have a look at the NameField to get the correct number of the Button. No need to attach a workbook as you may change Button1 to Button 4 in the code.

    Correct code for the last upload will look like:
    Please Login or Register  to view this content.
    If there only will be one button on the sheet you may try
    Please Login or Register  to view this content.
    Like stated: code may only work properly when one button is located on the sheet and not perform as expected when more than one button is located on the sheet.

    Ciao,
    Hiolger

  14. #14
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Easy way to assign Macro button

    Hello HiHoBe:

    I have tried every thing according to your instructions.
    But for some reason, it does not work and do noting.
    Please help and let me know.
    thx
    Riz

  15. #15
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Easy way to assign Macro button

    Hi, Riz,

    the first code wonīt work as somebody missed an assignment about the names of the buttons. Check the last one provided as in the first sample you provided the button on sheet2 was named differntly while in the last sample the names were split.

    Ciao,
    Holger

  16. #16
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Easy way to assign Macro button

    Hi, Riz,

    maybe this macro is what you were looking for (it looops through all Forms Buttons on each shet and will only attach a new macro when it finds one hoilding the old one):
    Please Login or Register  to view this content.
    Ciao,
    Holger

  17. #17
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Easy way to assign Macro button

    Hi HiHoBe:

    I think you have asolved my problem with the new thread with little different output.
    Once again, i thank you so much for such a great help.
    Riz

+ 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. Using VBA to assign a macro to a button
    By globalpontoon in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-25-2011, 04:10 AM
  2. Assign Macro to button
    By toby1 in forum Excel General
    Replies: 3
    Last Post: 07-12-2010, 11:23 AM
  3. Assign more than 1 macro to 1 button
    By Ramzes in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-16-2010, 10:14 AM
  4. A macro to create a form button, assign a macro and name the button
    By cl361 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-11-2008, 01:07 AM
  5. Cannot assign macro to button....HELP!!!
    By fry in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-09-2007, 05:43 AM

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