End Function
‘關閉Excel應用
Function CloseExcelApp(xlApp As Object)
On Error Resume Next
xlApp.Quit
Set xlApp = Nothing
End Function
’建立Excel應用
Function CreateExcelApp(QuitApp As Boolean) As Object
On Error Resume Next
Dim xlObject As Object
If CheckExcel Then
Set xlObject = GetObject(, “Excel.Application”)
If err.Number 0 Then
Set xlObject = Nothing
Set xlObject = CreateObject(“Excel.Application”)
CreateExcelApp = xlObject
Else
If QuitApp Then
xlObject.Quit
Set xlObject = Nothing
Set xlObject = CreateObject(“Excel.Application”)
End If
CreateExcelApp = xlObject
End If
End If
End Function
‘檢測EXCEL環(huán)境
Function CheckExcel() As Boolean
Dim xlCheckApp As Object
Set xlCheckApp = CreateObject(“Excel.Application”)
If xlCheckApp Is Nothing Then
MsgBox “對不起,系統未檢測到EXCEL安裝,請重新檢查EXCEL是否被正確安裝!”
CheckExcel = False
xlCheckApp.Quit
Set xlCheckApp = Nothing
Exit Function
Else