?
Solved

filling excel from c#

Posted on 2007-08-08
11
Medium Priority
?
187 Views
Last Modified: 2010-04-15
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?
0
Comment
Question by:g_johnson
  • 4
  • 4
  • 3
11 Comments
 
LVL 16

Expert Comment

by:Calvin Brine
ID: 19654374
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
 
LVL 4

Author Comment

by:g_johnson
ID: 19654436
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
 
LVL 23

Expert Comment

by:MalicUK
ID: 19654503
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:g_johnson
ID: 19654543
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
 
LVL 23

Expert Comment

by:MalicUK
ID: 19655019
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
 
LVL 4

Author Comment

by:g_johnson
ID: 19655061
But they might affect my users ...
0
 
LVL 16

Expert Comment

by:Calvin Brine
ID: 19655350
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
 
LVL 4

Author Comment

by:g_johnson
ID: 19655407
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
 
LVL 16

Accepted Solution

by:
Calvin Brine earned 1000 total points
ID: 19656212
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
 
LVL 16

Expert Comment

by:Calvin Brine
ID: 19656220
PS- closing the workbook and the app as well.
0
 
LVL 23

Assisted Solution

by:MalicUK
MalicUK earned 1000 total points
ID: 19660434
Agree, there is no foolproof way around this, and user education is going to be the way forward.

MUK.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question