在VB操作Excel时,如何遍历工作簿中的工作表?
在VB操作Excel时,如何遍历工作簿中的工作表,并将每张工作表的名字显示出来?
Set xlAppFilter = CreateObject("Excel.Application") '创建EXCEL应用类
Set xlBookFilter = xlAppFilter.Workbooks.Open(strFileNameForFilter)
xlBookFilter.Activate
Dim i, Count As Integer
Count = xlBookFilter.Sheets.Count
For i = 1 To Count
‘以下这句是错的,应该怎样写才是对的呢?
xlSheetsFilter = xlBookFilter.Sheets.Select(i)
msgbox xlSheetsFilter.Name
r = r + 1
Next
xlBookFilter.Close (True)
Set xlSheetFilter = Nothing
Set xlBookFilter = Nothing
xlAppFilter.Quit '关闭EXCEL应用类
Set xlAppFilter = Nothing '释放EXCEL应用类