0

I have a userform with 4 buttons.

I want to start the userform with button 1 already active.

The button is a public sub called "StartMeasButton_Click()" and is inside the userform. I need to click on that button.

I tried the Application.Run method but it fails, as I've understood, as the method is for a spreadsheet command button and not for a userform inside button.

1

3 Answers 3

1

Simplest solution: Make your button click call a subroutine, then you can call the subroutine whenever you want to "click" the button.

 Sub StartMeasButton_Click()
     MySubRoutine
 End Sub

 Sub MySubRoutine()
   'put the body of your click routine here
 End Sub

 Sub Form1_Initialise
     MySubRoutine  'effectively the same as clicking the button
  End Sub
Sign up to request clarification or add additional context in comments.

Comments

1

If you want to use code to "click" or "press" a command button just set the value to true. This will fire the commandbutton's code events.

UserForm1.CommandButton1.Value = True

1 Comment

miken32 while your edit is polite. The issue remains. OP questions need to be addressed more directly. I honestly think it'd be better to just delete this answer.
0

If it's allways the same "StartMeasButton" button, you can simply write a line like this:

StartMeasButton_Click

However, it can be dynamically generated if you use the "CallByName" method:

CallByName objForm, objButton.Name & "_Click", VbMethod

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.