.
Paste in the Sheet Module :
Option Explicit
Private Sub Worksheet_Activate()
CommandButton1_Click
End Sub
Sub CommandButton1_Click()
'Replace the MsgBox command with the macro desired.
MsgBox "It clicked !"
End Sub
Paste in ThisWorkbook Module :
Option Explicit
'Having to activate Sheet2 first because Excel activates/opens Sheet1 by default. Therefore, the button
'will not get auto-clicked.
'If the button is located on any other sheet, this Workbook_Open event is not required. When the user
'goes from Sheet1 to the Sheet in question, the Sheet_Activate event for that sheet will run the macro.
Private Sub Workbook_Open()
Application.ScreenUpdating = False
Sheets("Sheet2").Activate
Application.ScreenUpdating = True
Sheets("Sheet1").Activate 'This sheet has the button you want auto-clicked
End Sub
As indicated above, Excel opens Sheet1 by default unless otherwise instructed in the Workbook_Open event. If the command button you are targeting resides on Sheet1, these macros will do what you desire.
If the command button resides on any other sheet, the only macro required is the first two - you can ignore the ThisWorkbook_Module macros. NOTE: this macro relies on an ActiveX CommandButton ... not a
UserForm Button.
Hope this is understandable and that it helps.
Bookmarks