|
'*********************************************************************************************
' 函数说明:打开工作薄
' 参数说明:
' (1)ExcelSH:Excel中要使用的Sheet对象;
' (2)sheetName:要打开的工作薄Sheet名称;
' (3)path:要打开的工作薄路径;
' 返回结果:
' (1)成功:工作表对象ExcelSH
' (1)失败:Nothing
' 调用方法:
' OpenExcel (excelSH, "Test Data","C:\Documents and Settings\Administrator\Desktop\Test_Data.xls")
' @Version 1.0
' @Version
'*********************************************************************************************
Function OpenExcel (byRef excelSH, filePath, sheetName)
On Error Resume Next
Set excelApp = CreateObject("Excel.Application")
excelApp.Visible = True
Set excelWK = excelApp.Workbooks.Open(filePath)
Set excelSH = excelWK.Worksheets(sheetName)
On Error GoTo 0
End Function
'*********************************************************************************************
' 函数说明:关闭Excel应用程序;
' 参数说明:
' (1)ExcelApp:Excel应用程序名称;
' 调用方法:
' CloseExcel(ExcelApp)
' @Version 1.0
' @Version
'*********************************************************************************************
Sub CloseExcel ()
On Error Resume Next
excelWK.Save
excelApp.Quit
Set excelSH = Nothing
Set excelWK = Nothing
Set excelApp = Nothing
err = 0
On Error GoTo 0
End Sub |
|