Microsoft Office Tutorials and References
In Depth Information
Disabling a UserForm’s Close Button
6.
Insert the following procedure into a general VBA module:
Private Sub KillTheForm()
Unload UserForm1
End Sub
When the workbook is opened, the Workbook_Open procedure is executed. The
procedure in Step 4 displays the UserForm. At that time, the UserForm’s Activate event
occurs, which triggers the UserForm_Activate procedure (see Step 5). This
procedure uses the OnTime method of the Application object to execute a procedure
named KillTheForm at a particular time. In this case, the time is five seconds after the
activation event. The KillTheForm procedure simply unloads the UserForm.
7.
As an option, you can add a small CommandButton named CancelButton , set its
Cancel property to True , and insert the following event-handler procedure in the
UserForm’s code module:
Private Sub CancelButton_Click()
Unload Me
End Sub
Doing so lets the user cancel the splash screen before the time has expired by pressing
Esc. In the example, I placed this small button behind another object so that it’s not visible.
Keep in mind that the splash screen isn’t displayed until the workbook is entirely
loaded. In other words, if you’d like to display the splash screen to give the user
something to look at while the workbook is loading, this technique won’t fill the bill.
If your application needs to run some VBA procedures at start-up, you can display the
UserForm modeless so that the code will continue running while the UserForm is
displayed. To do so, change the Workbook_Open procedure as follows:
Private Sub Workbook_Open()
UserForm1.Show vbModeless
‘ other code goes here
End Sub
Disabling a UserForm’s Close Button
When a UserForm is displayed, clicking the Close button (the X in the upper-right corner) will
unload the form. You might have a situation in which you don’t want the Close button to unload
the form. For example, you might require that the UserForm be closed only by clicking a
particular CommandButton.
 
Search JabSto ::




Custom Search