Microsoft Office Tutorials and References
In Depth Information
ListBox Techniques
ShtNum = ShtNum + 1
Next Sht
With ListBox1
.ColumnWidths = ”100 pt;30 pt;40 pt;50 pt”
.List = SheetData
.ListIndex = ListPos
End With
End Sub
The ListBox1_Click procedure follows:
Private Sub ListBox1_Click()
If cbPreview Then _
Sheets(ListBox1.Value).Activate
End Sub
The value of the CheckBox control (named cbPreview ) determines whether the selected sheet
is previewed when the user clicks an item in the ListBox.
Clicking the OK button (named OKButton ) executes the OKButton_Click procedure, which
follows:
Private Sub OKButton_Click()
Dim UserSheet As Object
Set UserSheet = Sheets(ListBox1.Value)
If UserSheet.Visible Then
UserSheet.Activate
Else
If MsgBox(“Unhide sheet?”, _
vbQuestion + vbYesNoCancel) = vbYes Then
UserSheet.Visible = True
UserSheet.Activate
Else
OriginalSheet.Activate
End If
End If
Unload Me
End Sub
The OKButton_Click procedure creates an object variable that represents the selected sheet.
If the sheet is visible, it’s activated. If it’s not visible, the user is presented with a message box
asking whether it should be unhidden. If the user responds in the affirmative, the sheet is
unhidden and activated. Otherwise, the original sheet (stored in a public object variable named
OriginalSheet ) is activated.
 
Search JabSto ::




Custom Search