filling excel from c#

In spite of having this .Visible = false code in place in a c# project:

                  oApp = new Excel.Application();
                  oApp.Visible = false;


If I try to open any (ohter) excel workbook while my project is running, it also opens the workbook that I am filling from code.

Is there something I can do to stop this from happening?
LVL 4
g_johnsonAsked:
Who is Participating?
 
Calvin BrineConnect With a Mentor Commented:
That would be my take on it, you might want to think about maybe buillding the program to make the changes directly to the workbook, then close and save it, and only have it open when it's required in order to make changes.  Don't know if this is an option or not, but it would lower the chance of an occurance of this issue substancially.

HTH
Cal
0
 
Calvin BrineCommented:
The reason this is happening is because excel opens workbooks in the default one available.  In this case, excel is open but not visible, so when you try and open it you end up having it opened by the hidden instance of excel.  To avoid this, create a second instance of the application, and use it to open the other workbooks.

oApp2=new Excel.Application();
oApp2.Workbooks.Open "C:\test.xls";

or something along these lines, since I don't know C# very well.
HTH
Cal
0
 
g_johnsonAuthor Commented:
That's helpful Cbrine, and I guess I wasn't clear on my question.  Sorry about that.  But the problem is when the user opens another workbook manually.  So, my app is running, the user opens Excel for other purposes, and my workbook loads.

Can that be solved?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
MalicUKCommented:
Hi g_johnson,

The problem is how Cal described - Excel uses the most recently opened instance of excel as the default, which will be the one you created in your code. So creating a second instance of excel AFTER you created the one running your app ~should~ solve the problem:

oApp2=new Excel.Application();
oApp2.Visible = true;

However, no addons will be available in this copy of Excel, nor will a writeable personal.xls file.

MUK.
0
 
g_johnsonAuthor Commented:
I don't understand what this means:

However, no addons will be available in this copy of Excel, nor will a writeable personal.xls file.

What are "addons" and what do you mean by "writeable personal.xls" file?

So, in summary, is this just a limitation of using Excel from code?
0
 
MalicUKCommented:
Hi,

I'm not being rude but to be honest if you are unsure as to what they are then missing them won't affect you ;)

And yes, that is an accurate summary.

MUK.
0
 
g_johnsonAuthor Commented:
But they might affect my users ...
0
 
Calvin BrineCommented:
If you are installing this on multiple PC's then I would say there is a good chance someone is going to be using an addin.

Cal
0
 
g_johnsonAuthor Commented:
so do we all agree that this is just something the users need to be aware of?   That there is no good coding solution?
0
 
Calvin BrineCommented:
PS- closing the workbook and the app as well.
0
 
MalicUKConnect With a Mentor Commented:
Agree, there is no foolproof way around this, and user education is going to be the way forward.

MUK.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.