Introduce DataBase,Asp.net,JavaScript,Xml,Html,Css,Sql,Php,ASP.NET Controls,AJAX,Tools,HTML,CSS,JavaScript,Open Source Project,WPF,.Net Framework,Linq
Top Recommended Hosting

Visual Studio Tools for Office Opening multiple instances of Excel using C# and interop

by the3factory 4/14/2008 2:35:00 AM
Visual Studio Tools for Office Opening multiple instances of Excel using C# and interop
Question:
Using C# and Office Interop, I am opening 2 different copies of a 
workbook (I manually copy workbook1.xls to workbook2.xls).Both
workbook1 and workbook2 have exactly same copies of the macros.  From
the interop, I am calling macros in workbook1 and workbook2.  I am
able to do this successfully but I am worried about 1 thing.  At
different points in the macro, I call application.calculate and then
reset it back to manual.  My worry is that the calculation settings in
one workbook would affect the processing of the other workbook.
Anybody can throw light on this?

Basically from a code standpoint, I am doing the following:


oExcel1 = new Excel.ApplicationClass();
oExcel2 = new Excel.ApplicationClass();

oExcel1.Workbooks.Open(workbook1);
oExcel2.Workbooks.Open(workbook2);

oExcel1.GetType().InvokeMember("Run",........"Macro1")
oExcel2.GetType().InvokeMember("Run",........"Macro1")

Answer1:

You're off-topic with this question here, in the VSTO forum. VSTO provides tools to extend the UI of certain Office 2003 and 2007 applications. Interop and working with multiple application instances are not part of these tools, and thus not supported here.

 

The Please Read First message at the top of the forum lists links to Office-related newsgroups, please consult it. For this question, I recommend the excel.programming newsgroup, and perhaps an office.developer group. Probably best, in the Excel group, to leave out the fact that you're using C# - your problem would be relevant if you were using classic VB, too, which is where most of the top devs in that group come from.

 




-- Cindy Meister (VSTO/Word MVP)
Answer2:

Hi Andy,

 

My opinion is the Calculation setting will not affect on each other workbook because your codes create two Excel.Application COM Server. And the two workbooks are opened in different Excel Application. Each of the application objects should keep their own setting in different memory. But having a test on your end will give an accurate answer always.

 

Thanks

Ji

 




Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Related posts

Sign up for PayPal and start accepting credit card payments instantly.


Powered by BlogEngine.NET 1.2.0.0