+ Reply to Thread
Results 1 to 6 of 6

How to find the VBA code of a button without clicking it??

  1. #1
    Registered User
    Join Date
    10-19-2012
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    4

    How to find the VBA code of a button without clicking it??

    I received a excel file and it has all these buttons and codes. How do I quickly find out which VBA code a button is linked to without clicking it?

    When I click this button, the code that runs hangs this program so I have to Ctrl Alt Delete to kill it.

    I can't right click or anything.
    Last edited by arlu1201; 10-19-2012 at 11:16 AM. Reason: No bad language allowed. Kindly refrain.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How to find the VBA code of a button without clicking it??

    Your post does not comply with Rule 6 of our Forum RULES. Common courtesy is the order of the day. Avoid coarse language, provide feedback to suggested solutions, and take the time to thank those who took their time to help you.

    Coming back to your question. Press Alt+F11 on your file. It will take you to a code window. You should find some code headers like commandbutton1_click() or something which will tell you its the code for that button.

    If not, then just attach the file after removing all sensitive data and we can help you out.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    10-19-2012
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: How to find the VBA code of a button without clicking it??

    ok thanks for the reply.

    Now, what if the VBA code window has 5000 functions? There are headers like commandbutton534_click().

    Do I do through them all and put a msgbox("hi you clicked me on button XXX") in each of them, 5000 times?

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

    Re: How to find the VBA code of a button without clicking it??

    You can right click a button and either select View code (ActiveX) or Assign Macro... (Forms) to find the code associated with the button.

    It sounds like you might be dealing with quite a few so it might be worth watching out for any sort of pattern in the code.

  5. #5
    Registered User
    Join Date
    08-15-2012
    Location
    Las Vegas
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: How to find the VBA code of a button without clicking it??

    It depends on what type of buttons you have.

    If you have a Form Control button then right-click on the button and select "Assign Macro". You should see a box at the top that says "Macro Name". In that box you should see something that looks like this "Book1!Sheet1.Test2Button". The portion Book1 just tells you the name of the workbook (Excel file) that the macro is in. !Sheet1 tells you that the macro is in the sheet module for the sheet named Sheet1. Your button may not have that portion if the macro is in a standard module. The actual name of the sub that runs when the button is select is Test2Button. You can pull up the VBA editor using Arlette's instructions above and do a search for that macro name to find it.

    If you have an ActiveX control button instead the easiest way to find the code is to enter Design Mode. You can find this under the developer tab at the top of the screen. If you don't see the Developer tab you need to activate it by going to File --> Options --> Customize Ribbon and then checking the box in the right window next to Developer. Once in Design Mode, simply double-click on the button. The VBA editor should pop up and you should be in a sub that looks something like this:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-19-2012
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: How to find the VBA code of a button without clicking it??

    Quote Originally Posted by g8r777 View Post
    It depends on what type of buttons you have.

    If you have a Form Control button then right-click on the button and select "Assign Macro". You should see a box at the top that says "Macro Name". In that box you should see something that looks like this "Book1!Sheet1.Test2Button". The portion Book1 just tells you the name of the workbook (Excel file) that the macro is in. !Sheet1 tells you that the macro is in the sheet module for the sheet named Sheet1. Your button may not have that portion if the macro is in a standard module. The actual name of the sub that runs when the button is select is Test2Button. You can pull up the VBA editor using Arlette's instructions above and do a search for that macro name to find it.

    If you have an ActiveX control button instead the easiest way to find the code is to enter Design Mode. You can find this under the developer tab at the top of the screen. If you don't see the Developer tab you need to activate it by going to File --> Options --> Customize Ribbon and then checking the box in the right window next to Developer. Once in Design Mode, simply double-click on the button. The VBA editor should pop up and you should be in a sub that looks something like this:

    Please Login or Register  to view this content.
    Oh ok, design mode is the key.

    Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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