How to execute a CommandButton_Click macro without clicking on

G

Guest

Hi,
The Userform2 is opened from a Userform1 click. So, at the execution of the
CommandButton1, after UserForm2.Show line, I'm wondering if it's possible to
execute the macro inside CommandButton2_Click as if the user clicked on.
Thanks!!
Alex
Private Sub CommandButton1_Click()
UserForm1.Hide
Load UserForm2
UserForm2.CommandButton2.BackColor = RGB(166, 182, 214)
UserForm2.CommandButton2.SetFocus
'Something like Userform2.Browse.ExecuteMacro ??
UserForm2.Show
End Sub
 
P

paul.robinson

Hi
Commandbutton2 must call a macro, so simply do

Call myMacro

Your Commandbutton2_Click macro would be

Private sub Commandbutton2_Click ()
Call myMacro
End sub

and myMacro would be in a normal code module (cut and paste your
existing code out of Commandbutton2_Click ).
regards
Paul
 
R

RB Smissaert

Do:

Public Sub CommandButton1_Click()

Then you can do:

UserForm2.CommandButton1_Click

RBS
 
G

Guest

Since you're displaying UserForm2 as a modal dialog, you can call the
commandbutton2_click subroutine in the Activate event of Userform2. So, in
UserForm2 code module:

Private Sub UserForm_Activate()
CommandButton2_Click
End Sub
 
P

paul.robinson

Cool
I knew public variables in form code are properties of the form, but
this never occured to me.
Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top