Is it possible to run the code assigned to commandbutton1 on userform1 without opening the userform?
O ordnance1 May 11, 2010 #1 Is it possible to run the code assigned to commandbutton1 on userform1 without opening the userform?
C Chip Pearson May 11, 2010 #2 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
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
D Dave Peterson May 11, 2010 #3 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
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