+ Reply to Thread
Results 1 to 5 of 5

Clicking a FORM CONTROL Button using VBA code.

Hybrid View

  1. #1
    Registered User
    Join Date
    06-16-2015
    Location
    India
    MS-Off Ver
    2007
    Posts
    4

    Clicking a FORM CONTROL Button using VBA code.

    Hello everyone,

    Is it possible to "click" a form control button using VBA code?

    Background:

    I have a workbook whose VBA code is locked so I cannot see the macro. I can only give inputs and click on a "RUN" button [Form control button] to generate output.
    I want to do this using a VBA code. It possible to put inputs and get the outputs but I am not able to figure out a way to actually 'click' the button programically.

    The button is a form control button.
    I do not have the access to the VBA code so I cannot call the macro associated with button.

    For ActiveX buttons:
    CommandButton1 = true ; will do the trick
    I wanted to know if something like this is possible for FORM control buttons.

    Thank you in advance!!

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Clicking a FORM CONTROL Button using VBA code.

    If you know the name of the button, you could use code like this
    Sub test()
        With Workbooks("Workbook1").Sheets(1).Shapes("Button 1")
            Application.Run .OnAction
        End With
    End Sub
    If you don't know the name of the button, you'll have to write routine to find that name out.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    06-16-2015
    Location
    India
    MS-Off Ver
    2007
    Posts
    4

    Re: Clicking a FORM CONTROL Button using VBA code.

    Hi mikerickson

    It worked!!

    Thank you so much for your help.

  4. #4
    Registered User
    Join Date
    10-11-2015
    Location
    Los Angeles
    MS-Off Ver
    2013
    Posts
    1

    Re: Clicking a FORM CONTROL Button using VBA code.

    Mike, when I tried your code on a new worksheet with one button, I get this error message:

    "Runtime error 9. Subscript out of range."

    with the this line highlighted:

    With Workbooks("Workbook1").Sheets(1).Shapes("Button 1")

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,259

    Re: Clicking a FORM CONTROL Button using VBA code.

    1. Is the name of your workbook correct ?
    2. Is your sheet with the button the first sheet in your workbook ?
    3. Is your button a FORM control button or an ActiveX control button ?
    4. Is the name of your button correct ?

+ 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. Iterating a procedure by clicking on a button in user form
    By shayan.ni in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-08-2013, 07:18 AM
  2. ActveX Control Button Not Working But Form Control Button is
    By MikeTruth in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-31-2012, 05:04 AM
  3. enabling a vba control form button in vba code
    By jeskit in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 02-27-2012, 06:56 PM
  4. Cancel button on form deletes text and needs clicking twice
    By johncassell in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-19-2010, 11:51 AM
  5. Form Control Option Button Code
    By Boston in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-20-2010, 02:30 PM

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