PC Review


Reply
Thread Tools Rate Thread

Add sheet to workbook

 
 
=?Utf-8?B?RG9ydGU=?=
Guest
Posts: n/a
 
      31st Oct 2006
Hi,

In a .net console application in C#, I need to create excel files, workbooks
and add sheets to the workbook.
I have added a reference to Microsoft Excel 10.0 object library.

But I get a COM exception when I try to add a sheet to the workbook. Here is
my code:

Excel.Application ExcelApp = new Application();

// bug work around, due to local settings different than English version of
Excel
System.Threading.Thread.CurrentThread.CurrentCulture = new
System.Globalization.CultureInfo("en-US");

Excel.Workbook book1 = ExcelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
book1.Sheets.Add(null, book1.Sheets[1], 1, XlSheetType.xlWorksheet);

The last line of code generates the following error:
Exception from HRESULT: 0x800A03EC
error code:-2146827284

Could anyone tell me how I can add sheets to the workbook without getting an
error?

Thanks,
Dorte

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Save each sheet of multi-sheet workbook as a single-sheet workbook CTB Microsoft Excel Programming 3 17th May 2011 08:40 AM
Help needed: Getting all sheet setup data from one workbook toanother workbook Lostguy Microsoft Excel Programming 1 8th Jul 2008 02:43 PM
Copy Range to a New WorkBook + Name Sheet a cell Value + Name WorkBook another Celll Value Corey Microsoft Excel Programming 2 2nd Nov 2006 05:01 AM
Select sheet tabs in workbook & save to separate workbook files =?Utf-8?B?c3RyYXRvY2FzdGVy?= Microsoft Excel Worksheet Functions 2 1st Mar 2006 03:35 PM
Calling a Personal.XLS Sub from anther workbook's 'This Workbook' Sheet Activate Jack Gillis Microsoft Excel Discussion 2 21st Mar 2005 11:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:39 AM.