Answer the question
In order to leave comments, you need to log in
How to open an Excel document in a separate process?
When the application is running, a report is written to Excel. If at the same time another document is opened in Excel in parallel, then the following code will close both the Excel document opened using COM and the file that is not related to the application:
Dim w As Workbook
For Each w In mExcel.Workbooks
w.Save()
Next
mExcel.Quit()
Answer the question
In order to leave comments, you need to log in
Quit will always close all documents that are open.
There are several ways out: First, the created book should be closed using the Close() method. Further, before creating reports, you can count the number of open books in the connected Excel, and if there were no open books, you can safely close the Quit method, if there were open books, then do not close.
Secondly, when creating and connecting to COM, you can specify that a new instance of Excel is required. Unfortunately, this parameter is often hidden behind com wrappers and is not available for passing.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question