你这个已经封装在一个FUNCTION里了啊,
每次用直接用这个Function就行了,创建和释放交给计算机做就行了。
这样就行了作者: fsweicaixia 时间: 2013-9-13 16:12
我是懒得重复写,
我修改成这样了
Dim excelApp 'As Excel.Application
Dim oWorkbook 'As Excel.workbook
Dim oSheet 'As Excel.worksheet
Function createExcel(excelApp,oWorkbook,oSheet,filepath,oSheetName)
set excelApp = CreateObject("excel.application")
set oWorkbook = excelApp.Workbooks.Open(filepath)
' set oSheet = excelApp.Sheets.Item(1)
set oSheet =oWorkbook.Worksheets(oSheetName)
End function
Function CloseExcel(excelApp,oWorkbook,oSheet)
excelApp.Quit()
set oSheet = Nothing
set oWorkbook = Nothing
set excelApp = Nothing
End function
每次创建和关闭的动作反正是用计算机完成的,大可不必省去。
难道还怕电脑累着不成?
到是你如果只在脚本前后只是用一次打开和关闭动作,如果半路脚本出现了问题场景恢复后重新执行,或者半路终止运行之类的情况,难道你不怕Excel读取进程未关闭造成下一轮的测试失败?作者: fsweicaixia 时间: 2013-9-16 11:38
我贴脚本出来吧
Function getCellValue(ByVal filepath,ByVal columnname,ByVal columnValue,ByVal columnum)
'' Err = 0
' On Error Resume Next
createExcel excelApp,oWorkbook,oSheet,filepath,"Sheet1"
M = oSheet.UsedRange.Count'统计含有数据单元格
' msgbox M
Set oCell = oSheet.Range(columnname & M).Find(columnvalue)'查找功能点编号为ModuleCade单元格
If oCell Is Nothing Then
GetDataCoordinate = "Not Found"
Else
rnum = oCell.Row
getCellValue = oSheet.cells(rnum,columnum)
End if
CloseExcel excelApp,oWorkbook,oSheet
End Function
Function getRowCount(excelPath)
Set excelApp = CreateObject("excel.application")
Set oWorkbook = excelApp.Workbooks.Open(excelPath)
Set oSheet = excelApp.Sheets.Item(1)
getRowCount = oSheet.UsedRange.Rows.Count
CloseExcel excelApp,oWorkbook,oSheet
End Function
Function createExcel(excelApp,oWorkbook,oSheet,filepath,oSheetName)
set excelApp = CreateObject("excel.application")
set oWorkbook = excelApp.Workbooks.Open(filepath)
' set oSheet = excelApp.Sheets.Item(1)
set oSheet =oWorkbook.Worksheets(oSheetName)
End function
Function CloseExcel(excelApp,oWorkbook,oSheet)
excelApp.Quit()
set oSheet = Nothing
set oWorkbook = Nothing
set excelApp = Nothing
End function作者: linglvchao 时间: 2013-9-23 14:38
好高端、求指教、作者: fsweicaixia 时间: 2013-9-29 15:42
一点也不高端 就是拆分了一下 懒得每次都要写作者: fsweicaixia 时间: 2013-9-29 15:44
一点也不高端 就是拆分了一下 懒得每次都要写