我正在尝试通过脚本在 Excel 电子表格中插入一列。我发现下面的代码应该允许我插入一列,但是我将如何像在 Excel 应用程序中使用 fill>down 或 fill>series 命令那样用数据填充该列?
Const xlToRight = -4161
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWB = objExcel.Workbooks.Open("C:\Temp\Scripts\Test2.xls")
Set objSheet = objwb.Sheets("Overall")
objSheet.Columns("D:D").Insert xlToRight
objWB.Close True
objExcel.Quit
编辑
这就是最终的工作。
Const xlToRight = -4161
const xlColumns = &H2
const xlLinear = -4132
const xlDay = 1
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWB = objExcel.Workbooks.Open("C:\Temp\Scripts\Test2.xls")
Set objSheet = objwb.Sheets("Overall")
objSheet.Columns("A:A").Insert xlToRight
objSheet.Cells(1, 1).Value = "label"
objSheet.Cells(2, 1).Value = "Value"
set Range = objSheet.Range("A2:A"&objSheet.UsedRange.Rows.Count)
Range.FillDown
objSheet.Columns("A:A").Insert xlToRight
objSheet.Cells(1, 1).Value = "series"
objSheet.Cells(2, 1).Value = 1
set Range = objSheet.Range("A2:A"&objSheet.UsedRange.Rows.Count)
Range.DataSeries xlColumns, xlLinear,xlDay, 1, , False
objWB.Close True
objExcel.Quit