select工作表与多个工作簿打开crahses

如果我只创build一个工作簿,以下工作正常

Dim oXl As New Microsoft.Office.Interop.Excel.Application Dim wb_main As Workbook wb_main = oXl.Workbooks.Add ...add sheets and data to sheets CType(wb_main.Worksheets(1), Worksheet).Select() wb_main.SaveAs(Filename:=_files(0)._file_path.parentDir.parentDir & "out.xlsx") 

但有两个打开,我得到一个错误。 互操作错误不是简单易懂的debugging。

 Dim oXl As New Microsoft.Office.Interop.Excel.Application Dim wb_main As Workbook Dim wb_extended As Workbook wb_main = oXl.Workbooks.Add wb_extended = oXl.Workbooks.Add ...add sheets and data to sheets in both workbooks, no particular order CType(wb_main.Worksheets(1), Worksheet).Select() wb_main.SaveAs(Filename:=_files(0)._file_path.parentDir.parentDir & "out.xlsx") 

我得到一个错误HRESULT:0x800A03EC使用Excel 2013.谷歌的错误显示了很多人有不同的问题,据我所知。

.Select()仅适用于活动工作簿。 select之前的wb_main.Activate()将解决问题。

第二个工作簿是开放的。 使用直接分配的variables编辑工作簿不会更改活动工作簿。