gpt4 book ai didi

excel - 在 Excel 中添加新工作表(vbscript 控制)

转载 作者:行者123 更新时间:2023-12-04 20:06:37 24 4
gpt4 key购买 nike

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

关于excel - 在 Excel 中添加新工作表(vbscript 控制),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28018110/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com