J
jfcby
Hello,
I created a form in workbook1 that will access all open workbooks.
This is my problem I have 2 listboxes; listbox1 is in the
UserForm_Initialize() event which adds all open workbooks to it. Now I
need, when a workbook in ListBox1 is clicked it adds all worksheets in
listbox2. Below is the following code I've tried and does not work:
'====>> This adds the workbook names to listbox1
Private Sub UserForm_Initialize()
Dim wb As Workbook
With ListBox1
For Each wb In Workbooks
.AddItem (wb.Name)
Next wb
.ListIndex = 1
End With
End Sub
'<<====
'====>> This does not add worksheets to listbox2 when workbook is
clicked in listbox1
'Tried Code1 also with the Change_event:
Private Sub ListBox1_Click()
Dim wks As Worksheet
With ListBox2
For Each wks In ActiveWorkbook.Worksheets
.AddItem (wks.Name)
Next
End With
End Sub
'Tried Code2 also with the Change_Event:
Private Sub ListBox1_Click()
Dim wks As Worksheet
ListBox2.AddItem(wks.Name) = ListBox1.Value
End Sub
Thank you for your help,
jfcby
I created a form in workbook1 that will access all open workbooks.
This is my problem I have 2 listboxes; listbox1 is in the
UserForm_Initialize() event which adds all open workbooks to it. Now I
need, when a workbook in ListBox1 is clicked it adds all worksheets in
listbox2. Below is the following code I've tried and does not work:
'====>> This adds the workbook names to listbox1
Private Sub UserForm_Initialize()
Dim wb As Workbook
With ListBox1
For Each wb In Workbooks
.AddItem (wb.Name)
Next wb
.ListIndex = 1
End With
End Sub
'<<====
'====>> This does not add worksheets to listbox2 when workbook is
clicked in listbox1
'Tried Code1 also with the Change_event:
Private Sub ListBox1_Click()
Dim wks As Worksheet
With ListBox2
For Each wks In ActiveWorkbook.Worksheets
.AddItem (wks.Name)
Next
End With
End Sub
'Tried Code2 also with the Change_Event:
Private Sub ListBox1_Click()
Dim wks As Worksheet
ListBox2.AddItem(wks.Name) = ListBox1.Value
End Sub
Thank you for your help,
jfcby