vb调用excel两个sheet。

我想完成这样的功能:从第一个sheet提取某单元格经过简单计算后写入第二个sheet中。例如:ExcelSheet2.cells(n, 2)=ExcelSheet1.cells(n, 1)+ExcelSheet.cells(n, 2)。下面的代码错在哪里呢?老提示在当前位置发现该文件,问是否替换。而我选是时,excel却并未改变。

Set objexcel1 = CreateObject("Excel.application")
Set objworkBook1 = objexcel1.Workbooks.Open("d:商品信息库.xls", 3, False)
Set ExcelSheet1 = objworkBook1.Worksheets(1)

objexcel1.Visible = False

Set objexcel2= CreateObject("Excel.application")
Set objworkBook2 = objexcel2.Workbooks.Open("d:商品信息库.xls", 3, False)
Set ExcelSheet2 = objworkBook2.Worksheets(2)

objexcel2.Visible = False

For n = 2 To 6

ExcelSheet2.cells(n, 6) = ExcelSheet2.cells(n, 6) + ExcelSheet1.cells(n, 3)
objworkBook2.save

Next n

objworkBook1.Close

objworkBook2.Close
你说的“excel却并未改变”是粗销指修改后的数据没有保存吗?
提示出现是因为下一句:
objworkBook2.save
你用了两个workbook对象打开同一个文件,保存时冲突了。
修改后的代码:
Set objexcel1 = CreateObject("Excel.application")
Set objworkBook1 = objexcel1.Workbooks.Open("d:商品信息库.xls", 3, False)
Set ExcelSheet1 = objworkBook1.Worksheets(1)
Set ExcelSheet2 = objworkBook1.Worksheets(2)
objexcel1.Visible = False

For n = 2 To 6
ExcelSheet2.cells(n, 6) = ExcelSheet2.cells(n, 6) + ExcelSheet1.cells(n, 3)

Next n
objworkBook1.save
objworkBook1.Close
set objworkBook1=nothing
objexcel1.quit
set objexcel1=nothing

运岩游游行上述代码磨段该Excel文件不能在打开状态。
不会