2 liangte liangte 于 2016.04.11 09:51 提问

vbs写excel指定区域,报缺少Environment对象

Public Function WriteRep(sStatus,sDetails,xmlpath)
Dim fso
Dim oExcel
Dim ExcelFile
Dim TestcaseName
Dim objWorkBook
Dim objSheet
Dim NewTC
Dim Status
Dim Environment
Set fso = CreateObject("scripting.FileSystemObject")
Set oExcel = CreateObject("Excel.Application")
Status=UCase(sStatus)
oExcel.Visible = false 'True
TestcaseName = GetXmlNodeValue(xmlpath,"//DName")'Environment("TCase")
Set objWorkBook = oExcel.Workbooks.Open(ReportExcelFile)
Set objSheet = oExcel.Sheets("测试结果")
Set Environment = oExcel.ActiveCell.CurrentRegion
With objSheet
'设置行数和是否NewTc标识
Environment.Value("Row") = .Range("C7").Value + 11
NewTC = False
If TestcaseName <> objSheet.Cells(Environment("Row")-1,2).value Then
.Cells(Environment("Row"),2).value = TestcaseName
.Cells(Environment("Row"), 3).Value = Status
.Cells(Environment("Row"), 4).value = sDetails
.Cells(Environment("Row"), 5).value = GetXmlNodeValue(xmlpath,"//Res")
Select Case Status
Case "FAILED"
.Range("C" & Environment("Row")).Font.ColorIndex = 3
Case "PASS"
.Range("C" & Environment("Row")).Font.ColorIndex = 50
Case "WARNING"
.Range("C" & Environment("Row")).Font.ColorIndex = 5
End Select
NewTC = True
.Range("C7").Value = .Range("C7").Value + 1
'设置边界
.Range("B" & Environment("Row") & ":E" & Environment("Row")).Borders(1).LineStyle = 1
.Range("B" & Environment("Row") & ":E" & Environment("Row")).Borders(2).LineStyle = 1
.Range("B" & Environment("Row") & ":E" & Environment("Row")).Borders(3).LineStyle = 1
.Range("B" & Environment("Row") & ":E" & Environment("Row")).Borders(4).LineStyle = 1
'设置字体和颜色
.Range("B" & Environment("Row") & ":E" & Environment("Row")).Interior.ColorIndex = 19
.Range("B" & Environment("Row")).Font.ColorIndex = 53
.Range("E" & Environment("Row")).Font.ColorIndex = 41
.Range("B" & Environment("Row") & ":E" & Environment("Row")).Font.Bold = True
End If
If (Not NewTC) And (Status = "FAIL") Then
.Cells(Environment("Row"), 3).Value = "Fail"
.Range("C" & Environment("Row")).Font.ColorIndex = 3
end If
'更新结束时间
.Range("C5").Value = Time
.Columns("B:D").Select
'.Columns("B:D").Autofit
End With

1个回答

caozhy
caozhy   Ds   Rxr 2016.04.12 00:21

你的Environment(从哪里来的,添加数据环境对象了么?
http://download.csdn.net/detail/lrnvb/3286220
http://www.docin.com/p-761279088.html

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!