Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkBook = objExcel.Workbooks.Add()
i=4
objExcel.cells(1,1) = "Test1"
objExcel.cells(1,1).Font.Bold = True
objExcel.cells(2,1) = "Steps No"
objExcel.cells(2,1).Font.Bold = True
objExcel.cells(2,2) = "Test Steps"
objExcel.cells(2,2).Font.Bold = True
objExcel.cells(2,3) = "Expected Result"
objExcel.cells(2,3).Font.Bold = True
objExcel.cells(2,4) = "Remarks"
objExcel.cells(2,4).Font.Bold = True
'Need to add a new sheet in the excel and add content to it
objWorkBook.SaveAs(strFile)
objExcel.Quit
我正在尝试创建Excel电子表格并向其中添加数据。默认情况下,内容在第一张工作表中进行更新。需要在第二张纸上添加内容。不确定如何在第二张纸中添加数据。
像这样
Set objWorkbook = objExcel.Workbooks.Add(1)
添加单页工作簿
Set objWorkSheet = objWorkbook.Sheets.Add
第二张工作表
短版
Dim objExcel, objWorkbook, objWorkSheet
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add(1)
Set objWorkSheet = objWorkbook.Sheets.Add
i = 4
With objWorkSheet
.Cells(1, 1) = "Test1"
.Cells(1, 1).Font.Bold = True
.Range("A2:D2") = Array("Steps No", "Test Steps", "Expected Result", "Remarks")
.Range("A2:D2").Font.Bold = True
End With
完整的代码
Dim objExcel, objWorkbook, objWorkSheet
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add(1)
Set objWorkSheet = objWorkbook.Sheets.Add
i = 4
With objWorkSheet
.Cells(1, 1) = "Test1"
.Cells(1, 1).Font.Bold = True
.Cells(2, 1) = "Steps No"
.Cells(2, 1).Font.Bold = True
.Cells(2, 2) = "Test Steps"
.Cells(2, 2).Font.Bold = True
.Cells(2, 3) = "Expected Result"
.Cells(2, 3).Font.Bold = True
.Cells(2, 4) = "Remarks"
.Cells(2, 4).Font.Bold = True
End With
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句