User Forms and List Boxes
"MikeM" schreef in bericht
...
I have a User Form and inside is a ListBox that shows a list of Different
Worksheets within the Workbook. I asked a collegue for help to write the
Code that when you click on the WorkSheet name in the workbook, it would
open
that workbook.
I copied his code into the ListBox from his workbook to mine into the Same
ListBox name. It does not work in mine but works fine in his!
I checked to make sure the Properties are similar between the 2 which they
are. What am I missing?
--
MJM
Better paste some code snippets next time, else how can we know what you're
missing?
Two subs below, one fills the listbox, the other one handles the
onclick-event.
'populate listbox with sheets
'when opening the form...
Private Sub UserForm_Activate()
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ThisWorkbook
For Each ws In wb.Sheets
ListBox1.AddItem ws.Name
Next
Set ws = Nothing
Set wb = Nothing
End Sub
'after clicking the listbox
'activate selected sheet and
'close the form
Private Sub ListBox1_Click()
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ThisWorkbook
Set ws = wb.Sheets(ListBox1.Text)
ws.Activate
Unload Me
Set ws = Nothing
Set wb = Nothing
End Sub
|