Running code from userform

  • Thread starter Thread starter ordnance1
  • Start date Start date
O

ordnance1

Is it possible to run the code assigned to commandbutton1 on userform1
without opening the userform?
 
You need to load the form into memory, but not show it.

Sub AAA()
Load UserForm1
UserForm1.CommandButton1_Click
End Sub

In the userform's code module, change the command button's Click
procedure from Private to Public.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
 
What do you mean by open?

If you mean load it into memory, then nope. You have to do that.

If you mean display it to the user, then you can run the code without doing that.

I create a small userform with a single commandbutton on it.

This was the code that was behind that userform:

Option Explicit
Private Sub CommandButton1_Click()
MsgBox "hi"
End Sub


Then I created a subroutine in a general module that looked like:

Option Explicit
Sub testme()
Load UserForm1
UserForm1.CommandButton1.Value = True
Unload UserForm1
End Sub
 
Back
Top