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 电子表格并向其中添加数据。默认情况下,内容会在第一个工作表中更新。需要将内容添加到第二个工作表。 不确定如何在第二张表中添加数据。
最佳答案
类似这样的事情
设置 objWorkbook = objExcel.Workbooks.Add(1)
添加单个工作表工作簿
设置 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
关于excel - 在 Excel 中添加新工作表(vbscript 控制),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28018110/