獲得Excel文件的sheet名稱和數(shù)量

字號:

Dim ex As Excel.Application
    Dim exwbook As Excel.Workbook
    Dim exsheet As Excel.Worksheet
    Dim x As String
    Dim shetcounts As Integer
    shetcounts = 0
    Set ex = CreateObject("Excel.Application")
    Set exwbook = ex.Workbooks.Open(ThisWorkbook.Path & "\Book1.xls")
    For Each ws In Worksheets
    MsgBox ws.Name
    Next ws
    '別忘了加上關閉EXCEL的代碼與釋放變量