Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default exception 0x800A03EC in excel

Hello

I need to save excel file, but the method saveas result in exception
HRESULT: 0x800A03EC
In System.Exception {System.Runtime.InteropServices.COMException}

I use this C# code:

/* ----------------- BEGIN CODE ----------------- */
using System;
using System.Collections.Generic;
using System.Text;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.Diagnostics;


namespace console

{

class Program

{
static Excel.Application xlApp;
static Excel.Workbook xlBook;
static Excel.Worksheet xlSheet1, xlSheet2, xlSheet3;
static Excel.AppEvents_WorkbookBeforeCloseEventHandler
EventDel_BeforeBookClose;
static Excel.DocEvents_ChangeEventHandler EventDel_CellsChange;
//InitializeComponent();
static void Main(string[] args)
{
try

{

//Start Excel, and then create a new workbook.
xlApp = new Excel.Application();
xlBook = xlApp.Workbooks.Add(Missing.Value);
xlBook.Windows.get_Item(1).Caption = "XL Event Test";
xlSheet1 = (Excel.Worksheet)xlBook.Worksheets.get_Item(1);
xlSheet2 = (Excel.Worksheet)xlBook.Worksheets.get_Item(2);
xlSheet3 = (Excel.Worksheet)xlBook.Worksheets.get_Item(3);
xlApp.Visible = false;
xlApp.UserControl = false;
xlSheet1.Activate();
xlSheet1.Cells[1, 2] = "tESTE";
xlApp.ActiveCell.FormulaR1C1 = "10";
xlApp.ActiveWorkbook.SaveAs("c:\teste.xls", "xls", "", "",
null, null, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode. xlNoChange,
null, null, null, null, null);

}

catch (Exception ex)

{

throw ex;

}

}

private void CellsChange(Excel.Range Target)

{

//This is called when any cell on a worksheet is changed.
Debug.WriteLine("Delegate: You Changed Cells " +
Target.get_Address(Missing.Value, Missing.Value,
Excel.XlReferenceStyle.xlA1, Missing.Value, Missing.Value) +
" on " + Target.Worksheet.Name);
}


private void BeforeBookClose(Excel.Workbook Wb, ref bool Cancel)
{
//This is called when you choose to close the workbook in Excel.
//The event handlers are removed, and then the workbook is closed
//without saving the changes.
Wb.Saved = true;
Debug.WriteLine("Delegate: Closing the workbook and removing
event handlers.");
xlSheet1.Change -= EventDel_CellsChange;
xlSheet2.Change -= EventDel_CellsChange;
xlSheet3.Change -= EventDel_CellsChange;
xlApp.WorkbookBeforeClose -= EventDel_BeforeBookClose;
}

}
}
/* ----------------- END CODE ----------------- */
Thanks in advance

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default exception 0x800A03EC in excel

The biggest issue I have with the SaveAs method in Excel, and there is no
way to turn it off is when overwriting an Excel file with the same file
name, the confirmation message box of verifying that you want to replace the
file in the locaion with the file currently open, which then stops the code
at that point. Even if you set the "DisplayAlerts" property to "False"
boolean value (or 0), it still happens with that particular situation. This
is why I do not use the "SaveAs" method on any workbook.

How to get around this issue?

Instead of using the "SaveAs" method, use the "SaveCopyAs" method as it does
the trick and avoids the confirmation message entirely.

There is one other distinction between the "SaveAs" method versus the
"SaveCopyAs" method. With the "SaveAs" method, any formulas of any open
workbook dependent on the workbook being saved via the "SaveAs" method, they
will adjust to the new location. Using the "SaveCopyAs" method, none of the
formulas will be adjusted, even if they are dependent on the workbook being
saved via the "SaveCopyAs" method. The main reason why this is the case,
the "SaveCopyAs" method is originally meant to be used as a backup method,
so if something happens to the primary file, you have a backup way of
retrieving the file without hurting anything. To retrieve the file from the
backup location, just use windows explorer to copy it from it's backup
location and paste it to the original location.

--

Sincerely,

Ronald R. Dodge, Jr.
Master MOUS 2000

"Joao Mossmann" wrote in message
...
Hello

I need to save excel file, but the method saveas result in exception
HRESULT: 0x800A03EC
In System.Exception {System.Runtime.InteropServices.COMException}

I use this C# code:

/* ----------------- BEGIN CODE ----------------- */
using System;
using System.Collections.Generic;
using System.Text;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.Diagnostics;


namespace console

{

class Program

{
static Excel.Application xlApp;
static Excel.Workbook xlBook;
static Excel.Worksheet xlSheet1, xlSheet2, xlSheet3;
static Excel.AppEvents_WorkbookBeforeCloseEventHandler
EventDel_BeforeBookClose;
static Excel.DocEvents_ChangeEventHandler EventDel_CellsChange;
//InitializeComponent();
static void Main(string[] args)
{
try

{

//Start Excel, and then create a new workbook.
xlApp = new Excel.Application();
xlBook = xlApp.Workbooks.Add(Missing.Value);
xlBook.Windows.get_Item(1).Caption = "XL Event Test";
xlSheet1 = (Excel.Worksheet)xlBook.Worksheets.get_Item(1);
xlSheet2 = (Excel.Worksheet)xlBook.Worksheets.get_Item(2);
xlSheet3 = (Excel.Worksheet)xlBook.Worksheets.get_Item(3);
xlApp.Visible = false;
xlApp.UserControl = false;
xlSheet1.Activate();
xlSheet1.Cells[1, 2] = "tESTE";
xlApp.ActiveCell.FormulaR1C1 = "10";
xlApp.ActiveWorkbook.SaveAs("c:\teste.xls", "xls", "", "",
null, null, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode. xlNoChange,
null, null, null, null, null);

}

catch (Exception ex)

{

throw ex;

}

}

private void CellsChange(Excel.Range Target)

{

//This is called when any cell on a worksheet is changed.
Debug.WriteLine("Delegate: You Changed Cells " +
Target.get_Address(Missing.Value, Missing.Value,
Excel.XlReferenceStyle.xlA1, Missing.Value, Missing.Value) +
" on " + Target.Worksheet.Name);
}


private void BeforeBookClose(Excel.Workbook Wb, ref bool Cancel)
{
//This is called when you choose to close the workbook in
Excel.
//The event handlers are removed, and then the workbook is
closed
//without saving the changes.
Wb.Saved = true;
Debug.WriteLine("Delegate: Closing the workbook and removing
event handlers.");
xlSheet1.Change -= EventDel_CellsChange;
xlSheet2.Change -= EventDel_CellsChange;
xlSheet3.Change -= EventDel_CellsChange;
xlApp.WorkbookBeforeClose -= EventDel_BeforeBookClose;
}

}
}
/* ----------------- END CODE ----------------- */
Thanks in advance



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
Exception from HRESULT: 0x800A03EC Samir1014 Excel Programming 2 September 13th 07 07:14 PM
SaveCopyAs generating the 0x800a03ec exception PromisedOyster Excel Programming 0 December 27th 06 09:05 AM
Exception from HRESULT: 0x800A03EC nano2k New Users to Excel 0 July 21st 06 12:15 PM
Exception from HRESULT: 0x800A03EC. at Microsoft.Office.Interop.Excel.WorkbookClass.get_VBProject() [email protected] Excel Programming 0 April 11th 06 04:40 PM
Chart.Export throws COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC. Steven Excel Programming 1 November 5th 03 06:59 PM


All times are GMT +1. The time now is 10:04 AM.

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"