Q:

In a form Click a Workbook name in listbox1 and see the Sheets of the WB in the Listbox2

In a User form I would like to display two listboxs . In the listbox1 I would display the Opened Workbooks with the Exception of the Personal Workbook; and  whenever I click one of the Workbooks in the Listbox1 I would like to display the Worksheets available in that workbook in the Listbox2. 
Doing some research I found the following code which represent how far I have been able to go about this:
Private Sub UserForm_Initialize()

    UserForm1.Caption = "Workbooks and Sheets"

    Dim wb As Workbook
    Dim n As Long

    For Each wb In Application.Workbooks
    ListBox1.AddItem wb.Name
    Next wb

    For n = 1 To ActiveWorkbook.Sheets.Count
    ListBox2.AddItem ActiveWorkbook.Sheets(n).Name

    Next n

End Sub

Also I found this Post in Here but I should be doing something wrong because when I run the code both list box appear without any content whatsoever. Do you know How could I get this code to Work?
Thank you

A:

You should create a subroutine that will refresh both list.  In this way, you can keep the open Workbook list up to date. 
Private Sub ListBox1_Click()
    RefreshListBoxes
End Sub

Private Sub UserForm_Initialize()
    RefreshListBoxes
End Sub

Sub RefreshListBoxes()
    Dim wb As Workbook, ws As Worksheet

    ListBox2.Clear
    If ListBox1.ListIndex > -1 Then
        On Error Resume Next
        Set wb = Workbooks(ListBox1.Value)
        On Error GoTo 0

        If wb Is Nothing Then
            MsgBox "Workbook not found: " & ListBox1.Value, vbCritical, "Try Again"
        Else
            For Each ws In wb.Worksheets
                ListBox2.AddItem ws.Name
            Next
        End If
    End If

    ListBox1.Clear
    For Each wb In Workbooks
        If Not wb.FullName Like "*Excel\XLSTART\PERSONAL.XL*" Then ListBox1.AddItem wb.Name
    Next

End Sub

