I want a list of each sheet in a workbook. Can someone tell me where I have gone wrong here?:
Sub ListSheets()
Dim exlObj As Object
Dim exlSht As Object
Set exlObj = CreateObject("Excel.Application")
Set exlSht = CreateObject("Excel.Sheet")
exlObj.Visible = True
With exlObj
.workbooks.Open "C:\SomeXLDoc.xls"
End With
For Each exlSht In exlObj.Worksheets
MsgBox exlSht.Name
Next exlSht
Set exlObj = Nothing
End Sub
Sub ListSheets()
Dim exlObj As Object
Dim exlSht As Object
Set exlObj = CreateObject("Excel.Application")
Set exlSht = CreateObject("Excel.Sheet")
exlObj.Visible = True
With exlObj
.workbooks.Open "C:\SomeXLDoc.xls"
End With
For Each exlSht In exlObj.Worksheets
MsgBox exlSht.Name
Next exlSht
Set exlObj = Nothing
End Sub