Monday 13 January 2014

How to get the worksheets of closed workbook and how to attach to ComboBox using VBA

Sub LoadSheets(ClosedWBook As String, ComboboxObject As ComboBox)
Dim Count As Integer
'Dim sh As Worksheets
Dim c As Worksheet

Application.ScreenUpdating = False

Workbooks.Open ClosedWBook
'Set sh = GetObject(ClosedWBook).Worksheets
Count = 0
'Dim ws As Worksheet
With ComboboxObject
    .Clear
    For Each c In ActiveWorkbook.Worksheets
        .AddItem c.Name, Count
        Count = Count + 1
        .ListIndex = 0
    Next
End With

ActiveWorkbook.Close

End Sub