How would you run “CommandButton1_Click” from VBA, I want the Marco to “Click” the button on a user form, I have tried Application.Run "CommandButton1_Click" but it will not work I get “Marco commandbutton1_Click can not be found. Thanks excel ‘97
If your are running calling this procedure from another module, you will need to specify the class module. If the button is in UserForm1 for example:
If in a worksheet:
9 years on...
Clicking CommandButton2 in worsheet1, which contains code:
Private Sub CommandButton2_Click()
Worked! Indeed, clicking button 2 gave made command button 1 run. Both buttons were in the same worksheet.
But replacing CommandButton1_Click with UserForm1.CommandButton1_Click
gave this error:
Compile error: Method or data member not found
The UserForm1 exists and CommandButton1 exist. CommandButton1 was created from the form toolbox. Attempts to change to Forms.UserForm1.CommandButton1_Click also fail.
Interstingly, with UserForm1.CommandButton1_Click code, the debugger highlights the first line of the subroutine of CommanButton2 in the worksheet. i.e. Private Sub CommandButton2_Click() gets highlighted!
Can anyone come up with a different way a worksheet button can 'click' a form based button?
My previous reading when skilling myself up to do OOP, warned me against making things Public which could remain Private. As such, it built an impenetrable wall around my thought processes to devise your solution.
Thanks for the workaround. I'm sure it will open my mind up to other possible solutions in other instances in the future.
P.S. I could move to Excel 2007, but don't want to fork out the money (which would give me no real advantage - as far as I can tell) and I actually want to resist MS's money making schemes. They've done well enough in making Excel '03. My OS is > XP however