sparky2205
Well-known Member
- Joined
- Feb 6, 2013
- Messages
- 507
- Office Version
- 365
- 2016
- Platform
- Windows
Hi folks,
I have a listbox that populates with a list of worksheet names when the workbook is opened.
The user then selects worksheets from the list to have visible or hidden.
What I'm trying to achieve is when the workbook is closed an reopened the users last selections in the listbox are retained.
This is the code I've been trying:
It returns the error: "Could not get the List property. Invalid property array index."
The code works fine without the IF statement, i.e. the ListBox is populated correctly with the list of worksheet names.
I think I'm missing an array here somewhere but I'm not sure how to implement it.
I have a listbox that populates with a list of worksheet names when the workbook is opened.
The user then selects worksheets from the list to have visible or hidden.
What I'm trying to achieve is when the workbook is closed an reopened the users last selections in the listbox are retained.
This is the code I've been trying:
VBA Code:
Private Sub Workbook_Open()
Dim N As Long
For N = 2 To ActiveWorkbook.Sheets.Count - 1
Sheets("Setup").ListBox1.AddItem ActiveWorkbook.Sheets(N).Name
If ActiveWorkbook.Sheets(N).Visible = False Then
Sheets("Setup").ListBox1.List(N).Selected = True
End If
Next N
Sheets("Setup").ListBox1.Height = Sheets("Setup").ListBox1.ListCount * 12
End Sub
The code works fine without the IF statement, i.e. the ListBox is populated correctly with the list of worksheet names.
I think I'm missing an array here somewhere but I'm not sure how to implement it.