Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.vsnet.vstools.office, microsoft.public.excel.programming,microsoft.public.dotnet.framework.interop, microsoft.public.dotnet.languages.csharp
external usenet poster
 
Posts: 1
Default Using Excel Interop via VS.NET 2005 to create and save a new Excelworksheet.. please help!

Guys,

Sorry for crossing multiple groups but I am at my wits end... Please
help!

Below is my code in C# (VS.NET 2005.. I have tried every combo I can
think of. Every "SaveAs"
call results in the strange HRESULT 0x800A03EC error. I have verified
that the
folder path exists and that "Everyone" has Full Control on it. I have
also
tried Missing.Value in place of nulls. :(

Thanx!

J'son

CODE:

//create initial excel sheet
GC.Collect(); //clear out any earlier instances
Excel._Application application = new Excel.Application();
application.Visible = false;

Excel._Workbook workbook = application.Workbooks.Add(Missing.Value);
Excel._Worksheet sheet = (Excel._Worksheet)workbook.ActiveSheet;

//format the titles
DataColumnCollection columns = results.Tables[0].Columns;
for (int i = 0; i < columns.Count; i++)
{
string rangeHeader = ColumnLetter(i + 1) + "1";
Excel.Range range = (Excel.Range)sheet.get_Range(rangeHeader,
rangeHeader);

range.Font.Bold = true;
range.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
range.Value2 = columns[i].ColumnName;
range.EntireColumn.AutoFit();
}

//save the workbook for now -- ERROR HITS HERE!

application.ActiveWorkbook.SaveAs(_filePath, Excel.XlFileFormat.
xlWorkbookNormal, null, null, false, false, Excel.XlSaveAsAccessMode.
xlNoChange, false, false, null, null, null);
workbook.Close(null, null, null);
application.Quit();

Thanx!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to save an Excel 2007 on CD, be able to open it using 2005 doinginventory Excel Discussion (Misc queries) 4 January 15th 08 06:08 PM
Create DLL in Visual Studio 2005 accessible by Excel 2002 Steve Excel Programming 3 August 6th 06 09:05 PM
Cannot create instance of C# COM server compile with VS 2005 Ray Lau[_2_] Excel Programming 0 June 22nd 06 09:07 AM
After Save Event (Interop) Jörgen Ahrens Excel Programming 4 February 20th 06 07:58 AM
Using interop.excel to open a workbook, the workbook doesn't ask to save changes. [email protected] Excel Programming 1 December 28th 05 10:23 PM


All times are GMT +1. The time now is 12:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"