Excel Automation - New Window

M

Mehul

I am doing Excel automation and I notice that after opening
Excel.Application() from my application, any new workbook that I open from my
desktop also opens up within this Excel container that is attached to my
application...which is undesirable for several reasons.

How can I make the workbooks stored on my machine open up in their own Excel
window that does not have any of my customizations (when doing automation, i
am adding new toolbar items to my excel...which i remove when my application
quits)

I hope my question is clear enough.

Thanks.
 
C

Cindy M.

Hi =?Utf-8?B?TWVodWw=?=,
I am doing Excel automation and I notice that after opening
Excel.Application() from my application, any new workbook that I open from my
desktop also opens up within this Excel container that is attached to my
application...which is undesirable for several reasons.

How can I make the workbooks stored on my machine open up in their own Excel
window that does not have any of my customizations (when doing automation, i
am adding new toolbar items to my excel...which i remove when my application
quits)

I hope my question is clear enough.
Your question is clear and it's common. Unfortunately there isn't really any way
to steer in which application instance file open from the Windows interface (as
opposed to using File/Open in the application). Usually, Windows takes the one
that was started most recently. You could *try*

- Quitting any existing instances of the application when yours starts, storing
information about settings and open files. Once your instance is running, start
a "user" instance and open things up again.

- Capturing the New and Open events for files and not allowing them in your
instance. Automate the other instance to perform the task instead.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
N

Nick M

Thanks Cindy! After reading your suggestions I had an idea. When you double
click an excel file and it opens in your hidden instance, it makes it
visible. Combine that with what you said where it targets the last instance
and all you need to do is this.

Launch your hidden excel instance, then launch another hidden excel instance
right after. Do all your work in Instance #1. When you go to clean
everything up, if Instance #2 is NOT hidden, the user has control of it so
skip cleaning it up.

Here's the basic code. I tested this in my application and it works. I cut
and pasted a couple of lines out of that into below so the portion below may
not compile! but it at least has concept.

Excel.Application ExcelApp = null;
Excel.Application ExcelApp2 = null;
try
{
ExcelApp = new Excel.Application();
ExcelApp.Visible = false;
ExcelApp.DisplayAlerts = false;
Excel.Application ExcelApp2 = new Excel.Application();
ExcelApp2.Visible = false;
}
finally
{
if(ExcelApp != null)
{
ExcelApp.Quit();
while(System.Runtime.InteropServices.Marshal.ReleaseComObject(ExcelApp)
ExcelApp = null;
}
if(!ExcelApp2.Visible)
{
ExcelApp2.Quit();
while(System.Runtime.InteropServices.Marshal.ReleaseComObject(ExcelApp2)
ExcelApp2 = null;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top