ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   macro command button click (https://www.excelbanter.com/excel-programming/427034-macro-command-button-click.html)

Woodi2

macro command button click
 
I have a macro that opens a userform. I want the macro to open userform 5
then upon opening userform 5 I want command button 3 to be activated. I have
made command button 3 public withing the code for userform 5. When the macro
is activated, the userform dispalys ok but the command button has not been
activated. I thought this might be a simple one but may be I was wrong.

Private Sub CommandButton1_Click()
UserForm5.Show
UserForm5.CommandButton3_Click
Unload Me
End Sub

Per Jessen

macro command button click
 
Harald, you are absolutely right.

Should have seen that.

Best wishes Per

"Harald Staff" skrev i meddelelsen
...
Per, I believe the code halts on Userform5.show and doesn't proceed until
the form unloads, therefore focus must be set before show:

Sub test()
Load UserForm5
UserForm5.CommandButton3.SetFocus
UserForm5.Show
End Sub

Purists will prefer this way of doing it:

Sub test2()
Dim UF5 As UserForm5
Set UF5 = New UserForm5
UF5.CommandButton3.SetFocus
UF5.Show
MsgBox "that's all, folks"
Set UF5 = Nothing
End Sub

Best wishes Harald

"Per Jessen" wrote in message
...
Hi

Private Sub CommandButton1_Click()
UserForm5.Show
UserForm5.CommandButton3.SetFocus
Unload Me
End Sub

Regards,
Per

"Woodi2" skrev i meddelelsen
...
I have a macro that opens a userform. I want the macro to open userform
5
then upon opening userform 5 I want command button 3 to be activated. I
have
made command button 3 public withing the code for userform 5. When the
macro
is activated, the userform dispalys ok but the command button has not
been
activated. I thought this might be a simple one but may be I was wrong.

Private Sub CommandButton1_Click()
UserForm5.Show
UserForm5.CommandButton3_Click
Unload Me
End Sub






All times are GMT +1. The time now is 05:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com