Microsoft Office Tutorials and References
In Depth Information
Creating an Add-In
A CommandButton near the bottom-left corner
of the UserForm, setting its Name property to
cmdOK , and its Caption property to OK.
A CommandButton near the bottom-right
corner of the UserForm, setting its Name property
to cmdExit , and its Caption property to Exit .
Your UserForm will end up looking like Figure 22-1.
The design work is complete for your UserForm. In the
UserForm module, enter the following code, which is mostly
triggered by the cmdOK button’s Click event. The requested
task will be performed depending on whichever OptionButton
was selected.
Private Sub cmdOK_Click()
figurE 22-1
‘Declare an Integer type variable to help loop
‘through the worksheets.
Dim intSheet As Integer
‘Open a Select Case structure to evaluate each OptionButton.
Select Case True
‘If OptionButton1 was selected:
‘Unhide all sheets.
Case OptionButton1.Value = True
For intSheet = 1 To Sheets.Count
Sheets(intSheet).Visible = xlSheetVisible
Next intSheet
‘If OptionButton2 was selected:
‘Hide all sheets except active sheet.
Case OptionButton2.Value = True
For intSheet = 1 To Sheets.Count
If Sheets(intSheet).Name <> ActiveSheet.Name Then
Sheets(intSheet).Visible = xlSheetHidden
End If
Next intSheet
‘If OptionButton3 was selected:
‘Protect all sheets.
Case OptionButton3.Value = True
For intSheet = 1 To Sheets.Count
Sheets(intSheet).Protect
Next intSheet
‘If OptionButton4 was selected:
‘Unprotect all sheets.
Case OptionButton4.Value = True
For intSheet = 1 To Sheets.Count
Sheets(intSheet).Unprotect
Next intSheet
Search JabSto ::




Custom Search