Class Excel
Private sExcelHandle,sWorkbookHandle,sWorksheetHandle
Sub Class_Initialize
'类的初始化,生成一个Excel Application对象,并将句柄保存在sExcelHandle
Set sExcelHandle = CreateObject("excel.Application")
sExcelHandle.Visible = True
End Sub
Function OpenExcel(Byval sExcelPath)
Set sWorkbookHandle = sExcelHandle.Workbooks.Open(sExcelPath)
End Function
Function SelectSheet(Byval sSheetName)
'Set sSheetHandle = sExcelHandle.Worksheets(sSheetName).Activate
Set sSheetHandle = sExcelHandle.Worksheets(sSheetName)
sSheetHandle.Activate
End Function
Function GetCellValue(Byval iRowNum,Byval iColNum)
GetCellValue = sExcelHandle.Cells(iRowNum,iColNum)
End Function
Sub SetCellValue(Byval iRowNum,Byval iColNum,Byval sCellValue)
sExcelHandle.Cells(iRowNum,iColNum) = sCellValue
End Sub
Sub closeExcel()
sWorkbookHandle.Save
sWorkbookHandle.Close
sExcelHandle.Quit
Set sSheetHandle = Nothing
Set sWorkbookHandle = Nothing
Set sExcelHandle = Nothing
End Sub
End Class
Set Excel = New Excel
oExcel.OpenExcel("R:\test\Case.xlsx")
oExcel.SelectSheet("Pkg_download")
MsgBox oExcel.GetCellValue(1,1)
oExcel.SetCellValue 1,2,"True"
oExcel.closeExcel()
Set Excel = Nothing