simulate click of commandbutton

birdman

Board Regular
Joined
Oct 11, 2005
Messages
187
is there vba code to automatically click a commandbutton if a userform appears?

this will not happen all the time. so i will have an if statement saying if this is true, click the commandbutton. thanks for any help in advance.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Steve

Is the command button on the userform?

What are you actually trying to do?
Code:
Private Sub CommandButton1_Click()
    MsgBox 1
End Sub

Private Sub UserForm_Initialize()
    CommandButton1_Click
End Sub
 
Upvote 0
Depends on what you want to achieve

If you want to access the code within a command button simply call it:

Code:
Call CommandButton1_Click
 
Upvote 0
yes the commandbutton is on the userform. i just need to commandbutton to be clicked as soon as the userform appears if a certain condition is true.

so if a condition is true, the userform appears and the button is clicked immediately to run the program.

if a condition is false, the userform appears and the user must click that same button to continue the program.

thanks for the response. i will try the provided code.
 
Upvote 0
i did plan to have the userform showing as the program was being run.

this program will analyze files in 2 separate folders, folder A and folder B.

if there are only files in folder A, userform A will open and the user can select certain things to do and click continue to analyze the files.

if there are only files in folder B, userform B will open and the user can select certain things to do and click continue to analyze the files.

if there are files in both folder A and folder B, userform A will appear, the user will select certain things to do and click continue. at this point userform B will appear, the user will select certain things to do and click continue. then userform A will reappear and the analysis will begin for folder A. once everything associated with userform A is complete, userform B will appear again and complete the analysis for folder B.

right now, when userform A and B reappear the second time, i need to click continue for the analysis to begin.
 
Upvote 0

Forum statistics

Threads
1,214,818
Messages
6,121,725
Members
449,049
Latest member
MiguekHeka

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top