问题描述
- vbs写excel指定区域,报缺少Environment对象
- Public Function WriteRep(sStatussDetailsxmlpath)
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"")-12).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
解决方案
你的Environment(从哪里来的,添加数据环境对象了么?
http://download.csdn.net/detail/lrnvb/3286220
http://www.docin.com/p-761279088.html
时间: 2024-11-29 06:05:06