Dim ExcelApp As Object
Dim Books As Object
Dim pdbz As Boolean
Dim xlBook As Object
Dim xlSheet As Object
On Error Resume Next
Set ExcelApp = GetObject(, "Excel.application")
If Err <> 0 Then
Err.Clear
Set ExcelApp = CreateObject("Excel.application")
If Err Then
MsgBox Err.Number & ":" & Err.Description '打开失败
Exit Sub
End If
Set xlBook = ExcelApp.WorkBooks.Open(App.Path & "\中药数据表.xls") '打开EXCEL工作簿
Else
pdbz = False
Set Books = ExcelApp.WorkBooks
For Each book In Books
If book.Name = "Excel展点(模板文件).xls" Then
pdbz = True
Set xlBook = book
Exit For
End If
Next
If pdbz = False Then
Set xlBook = ExcelApp.WorkBooks.Open(App.Path & "\中药数据表.xls") '打开EXCEL工作簿
End If
End If
ExcelApp.Visible = False '设置EXCEL可见
Set xlSheet = xlBook.Worksheets(1) '打开EXCEL工作表
xlSheet.Activate '激活工作表
温馨提示:答案为网友推荐,仅供参考