+ Reply to Thread
Results 1 to 7 of 7

Assign macro to a dynamic button using vba

  1. #1
    Forum Contributor
    Join Date
    11-09-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    390

    Assign macro to a dynamic button using vba

    Hi All,

    I am creating a new worksheet using vba and added a commandbutton to it using below code:

    Please Login or Register  to view this content.
    I have a piece of code and would like to assign to this button. the code is under sub LoadButton(). How can I assign the commandbutton using vba to call sub LoadButton ()?

    I really appreciate every help.

    Thanks,

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Assign macro to a dynamic button using vba

    You are creating an ActiveX button and you can't assign a macro to an ActiveX button.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    11-09-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    390

    Re: Assign macro to a dynamic button using vba

    So is there a way to create a button using vba and assign a piece of code to it when it is clicked?

    Quote Originally Posted by Norie View Post
    You are creating an ActiveX button and you can't assign a macro to an ActiveX button.

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Assign macro to a dynamic button using vba

    Hi,

    You can use a Form button instead:

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    11-09-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    390

    Re: Assign macro to a dynamic button using vba

    That is exactly what I was looking after. Thanks a lot you're a life saver!

    Quote Originally Posted by xlnitwit View Post
    Hi,

    You can use a Form button instead:

    Please Login or Register  to view this content.

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Assign macro to a dynamic button using vba

    Change Sheet1 to appropriate sheetname.
    Please Login or Register  to view this content.
    Last edited by bakerman2; 07-11-2016 at 04:43 AM.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  7. #7
    Forum Contributor
    Join Date
    11-09-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    390

    Re: Assign macro to a dynamic button using vba

    Thanks bakerman

    Quote Originally Posted by bakerman2 View Post
    Change Sheet1 to appropriate sheetname.
    Please Login or Register  to view this content.

+ 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. Assign Macro to Button
    By DanBlum in forum Excel General
    Replies: 1
    Last Post: 02-20-2012, 10:42 AM
  2. 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
  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. How to assign a macro to a button?
    By sailor64 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-03-2009, 01:34 PM
  5. Assign Macro to a Button
    By tt388 in forum Excel General
    Replies: 1
    Last Post: 10-26-2008, 09:40 AM
  6. 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
  7. Cannot assign macro to button....HELP!!!
    By fry in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-09-2007, 05:43 AM
  8. [SOLVED] How do I Assign Macro to a button?
    By BellExcel in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 05-20-2005, 03:06 PM

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