我想从一个 Excel 工作簿的工作表中总结一个范围并将其写入另一个工作簿。我想出了以下代码,但它不起作用。
1)它打开一个文件打开窗口,要求我选择要更新的工作簿
2)选择工作簿后,它会写入“0”作为值。
代码:
Dim xl1 As New Excel.Application
Dim xl2 As New Excel.Application
Dim wb1 As Excel.Workbook
Dim wb2 As Excel.Workbook
Dim st1 As Excel.Worksheet
Dim st2 As Excel.Worksheet
wb1 = xl1.Workbooks.Open("F:\excelsumtest\file1.xlsx")
wb2 = xl2.Workbooks.Open("F:\excelsumtest\file2.xlsx")
st1 = wb1.Worksheets(1)
st2 = wb2.Worksheets(1)
st2.Cells(1, 1).formula = "=Sum(st1!A1:S1)"
干杯