获取excel窗口求助
打开了几个excel,需要用VB的程序,对选定的工作簿中工作表的数据进行校对。在遍历excel窗口时地直没进展,其中MsgBox xlApp.Workbooks.name出错,MsgBox ws.name没反应 希望大家帮忙看看,谢谢。
sub a()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Dim wb As Workbook
Dim ws As Worksheet
Dim i As Integer
Set xlApp = New Excel.Application
'遍历所有打开的工作簿
For i = 1 To xlApp.Workbooks.Count
'获取工作簿对象
Set wb = xlApp.Workbooks(i)
MsgBox xlApp.Workbooks.name
'遍历所有工作表
For Each ws In wb.Worksheets
MsgBox ws.name
Next ws
Next i
'释放对象
Set ws = Nothing
Set wb = Nothing
Set xlApp = Nothing
end sub