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.
 

Some videos you may like

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,047
Office Version
  1. 365
Platform
  1. Windows
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
 

MichaelRo

Well-known Member
Joined
Jun 7, 2004
Messages
549
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
 

birdman

Board Regular
Joined
Oct 11, 2005
Messages
187
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.
 

birdman

Board Regular
Joined
Oct 11, 2005
Messages
187
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,118,057
Messages
5,569,955
Members
412,300
Latest member
Chaneycr
Top