+ Reply to Thread
Results 1 to 5 of 5

How do I run the macro for a button click without clicking the button?

  1. #1
    Registered User
    Join Date
    05-08-2012
    Location
    Golden, Colorado
    MS-Off Ver
    Excel 2010
    Posts
    77

    How do I run the macro for a button click without clicking the button?

    I have an embedded button and code that runswhen it is clicked.
    It is:
    Public Sub Show_Hide_Button_Click()
    I want to run that code when the workbook opens.
    So in the Workbook_Open() routine i have a line:
    Show_Hide_Button_Click
    But the compiler says the Sub or Function is not defined.

    Alternatively, I wild like to change the label on the button, but do not know how to reference it.
    Using this inside the Workbook_Open routine does not work
    Show_Hide_Button.Caption = "Show Sheets"
    It says the variable Show_Hide_Button is not defined.
    Suggestions?
    thanks

  2. #2
    Registered User
    Join Date
    05-08-2012
    Location
    Golden, Colorado
    MS-Off Ver
    Excel 2010
    Posts
    77

    Re: How do I run the macro for a button click without clicking the button?

    I figured this out, by referencing the caption as Sheets("Charts").Show_Hide_Button.Caption it worked.

  3. #3
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: How do I run the macro for a button click without clicking the button?

    For the on open event try

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    05-08-2012
    Location
    Golden, Colorado
    MS-Off Ver
    Excel 2010
    Posts
    77

    Re: How do I run the macro for a button click without clicking the button?

    That works too, thank you.

  5. #5
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: How do I run the macro for a button click without clicking the button?

    No problem! Don't forget to mark this thread solved and maybe give a star tap if I helped.
    Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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