• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Display file path in Listbox

Monty

Well-Known Member
Hello Experts.

Excel file attatched consists of One command button to refresh and two listboxes.

1) Wanted to display file names with the path in the listbox 1 which ever open workbooks found in the excel application.
2) when you click on the file name in the listbox1 should show tab names in the second listbox2.

Really appreciate for quick response.
 

Attachments

You can do something like below.
Code:
Public LB_1 As MSForms.ListBox
Public LB_2 As MSForms.ListBox

Sub Pop_LB1()
Dim i As Integer: i = 0
Dim wb As Workbook
Set LB_1 = ThisWorkbook.Sheets(1).OLEObjects("ListBox1").Object
LB_1.Clear
For Each wb In Application.Workbooks
    LB_1.AddItem pvargItem:=wb.Path & "\" & wb.Name
Next
End Sub

Sub WSList()
Dim ws As Worksheet
Dim i As Integer
Dim x As Variant

Set LB_1 = ThisWorkbook.Sheets(1).OLEObjects("ListBox1").Object
Set LB_2 = ThisWorkbook.Sheets(1).OLEObjects("ListBox2").Object
LB_2.Clear
For i = 0 To LB_1.ListCount - 1
    If LB_1.Selected(i) Then
        x = Split(LB_1.List(i), "\")
        For Each ws In Workbooks(x(UBound(x))).Worksheets
            LB_2.AddItem pvargItem:=ws.Name
        Next
    End If
Next i

End Sub
 
Back
Top