search
Twitter Rss Feeds
MicrosoftArticlesForumsGroups
C# .NET
VB.NET
Visual Studio .NET
ADO.NET
Xml/Xslt
VB 6.0
.NET CF
GDI+
LINQ
Deployment
Security
FoxPro
Silverlight / WPF
Entity Framework
RIA Services

Web ProgrammingArticlesForumsGroups
JavaScript
ASP
ASP.NET
Web Services

Non-MicrosoftArticlesForumsGroups
NHibernate
Perl
PHP
Ruby
Java
Linux / Unix
Apple
Open Source

DatabasesArticlesForumsGroups
SQL Server
Access
Oracle
MySQL
Other Databases

OfficeArticlesForumsGroups
Microsoft Excel
Microsoft Word
Microsoft Powerpoint
Publisher
Money

Operating SystemsArticlesForumsGroups
Windows 7
Windows Server
Windows Vista
Windows XP
Windows Update
MAC
Linux / UNIX

Server PlatformsArticlesForumsGroups
Share Point
BizTalk
Site Server
Exhange Server
IIS
Transaction Server

Graphic DesignArticlesForumsGroups
Macromedia Flash
Adobe PhotoShop
Microsoft Expression

OtherArticlesForumsGroups
Subversion / CVS
Ask Dr. Dotnetsky
Active Directory
Networking
Uninstall Virus
Job Openings
Reviews
Search Engines
Resumes

 

Previous Thread:   Excellent!

8/9/2005 11:16:07 PM    Excel Interop issues with a new spreadsheet
We have a C# application that is using the Excel object model via  
  
Interop.  
  
The code below works fine for an existing workbook, ie one that you  
  
have opened up (or saved), but if you open up Excel, click the New  
  
button, enter some data and then run the program below, an Exception is  
  
thrown:  
  
Exception for HRESULT: 0x800A03EC on the call to SaveCopyAs  
  
Is there a workaround? I have tried using the SaveAs method but to no  
  
avail.  
  
object missing =3D System.Reflection.Missing.Valu=ADe;  
  
object o =3D  
  
System.Runtime.InteropServices=AD.Marshal.GetActiveObject("Exce=ADl.Applica=  
  
tion");  
  
Excel._Application excelApp =3D o as Excel._Application;  
  
// connect to current Excel workBook  
  
Excel.Workbook workBook =3D excelApp.ActiveWorkbook;  
  
if (workBook =3D=3D null)  
  
{  
  
throw new ApplicationException("No workbook is currently  
  
defined");  
  
}  
  
string fileName  =3D "temp.xls";  
  
workBook.SaveCopyAs(fileName);  
  
workBook.Close  (missing  
  
,missing=20  
  
,missing);

8/16/2005 6:11:30 PM    Re: Excel Interop issues with a new spreadsheet
PromisedOyster wrote:  
  
Hi,  
  
the reason behind that is that the input in the cell is not finalized.  
  
Just finish by using Enter and it should work.  
  
Regards  
  
Dirk

8/16/2005 10:43:34 PM    Re: Excel Interop issues with a new spreadsheet
Thanks Dirk  
  
How can I finalise input in the cell programmatically.  
  
I have tried calling excelApp.SendKeys("~",object(false)) but to no  
  
avail.

8/17/2005 12:07:20 PM    Re: Excel Interop issues with a new spreadsheet
PromisedOyster wrote:  
  
If there is more than 1 sheet in the workbook then  
  
// don't activate the active sheet as this does not help  
  
Excel.Worksheet workSh=workBook.Sheets.get_Item(2) as Excel.Worksheet;  
  
workSh.Activate();  
  
//  instead of SaveCopyAs you may try the following  
  
//workBook.Close((object)true,(string)fileName,(object)false);  
  
workBook.SaveCopyAs(fileName);  
  
//I would use false instead of missing  
  
workBook.Close  ((object) false	,missing,missing);  
  
If there is only one sheet in the workbook I only see the possibility to  
  
inform the user to finalize the input. You can not even run a macro  
  
inside Excel in this state.  
  
Sorry  
  
Dirk

8/17/2005 12:52:04 PM    Re: Excel Interop issues with a new spreadsheet
PromisedOyster wrote:  
  
Another option could be to Activate Excels main window  
  
see http://www.codeproject.com/vb/net/ActivateSingleAppInstance.asp  
  
and then use System.Windows.Forms.SendKeys.Send  
  
to send either an Enter or an Escape  
  
Dirk


Pete's Blog   |    Pete's Resume   |    Robbe's Blog   |    Robbe's Resume   |    Archive #2   |    Archive #3   |    Dotnetslackers   |    XmlPitStop   |    Advertise   |   Contact Us   |   Privacy   |   Copyright (c) 2000 - 2009 eggheadcafe.com  All rights reserved.