Error Description
When running an Excel Copy and PasteSpecial application in an Excel Addin (VSTO.Interop) an error message 0x800A03EC is generated
error message
System.Runtime.InteropServices.COMException HResult=0x800A03EC Message=Ausnahme von HRESULT: 0x800A03EC Source=<Cannot evaluate the exception source> StackTrace: <Cannot evaluate the exception stack trace> |
Fault Line
Error in the program line:
new_Worksheet.PasteSpecial(XlPasteType.xlPasteValues); |
Solution:
You have to copy into a Worksheet.Range
//--< copy >-- active_Worksheet.UsedRange.Copy(); new_Worksheet.Cells[1,1].PasteSpecial(XlPasteType.xlPasteValues, XlPasteSpecialOperation.xlPasteSpecialOperationNone, false, false); //--</ copy >--
|
Solution: working copy code
Description: This code copies the current Excel.Sheet 1 under Excel and saves the Excel sheet as a pure values ββfile in another Excel file.
public void export_Sheet1() { //------------< export_Sheet1() >------------ //< init > Application excel_App =Globals.ThisAddIn.Application; Workbook active_Workbook = Globals.ThisAddIn.Application.ActiveWorkbook; Worksheet active_Worksheet = active_Workbook.Worksheets[1]; //</ init >
//< new > Workbook new_Workbook = excel_App.Workbooks.Add(); Worksheet new_Worksheet = new_Workbook.Worksheets[1]; //< new >
//--< copy >-- active_Worksheet.UsedRange.Copy(); new_Worksheet.Cells[1,1].PasteSpecial(XlPasteType.xlPasteValues, XlPasteSpecialOperation.xlPasteSpecialOperationNone, false, false); //--</ copy >--
//-< save >- string sFilename_New =active_Workbook.Path + "\\" + "Retouren_Daten"; if(File.Exists(sFilename_New) { File.Delete(sFilename_New); } new_Workbook.SaveAs(Filename:sFilename_New,ConflictResolution:XlSaveConflictResolution.xlLocalSessionChanges,AddToMru:false); //-</ save >-
//< end > new_Workbook.Close(); //</ end > //------------</ export_Sheet1() >------------ }
|
Bad example code
public void export_Sheet1() { //------------< export_Sheet1() >------------ //< init > Application excel_App =Globals.ThisAddIn.Application; Workbook active_Workbook = Globals.ThisAddIn.Application.ActiveWorkbook; Worksheet active_Worksheet = active_Workbook.Worksheets[1]; //</ init >
//< new > Workbook new_Workbook = excel_App.Workbooks.Add(); Worksheet new_Worksheet = new_Workbook.Worksheets[1]; //< new >
//--< copy >-- active_Worksheet.UsedRange.Copy(); new_Worksheet.Cells[1, 1].Select(); new_Worksheet.PasteSpecial(XlPasteType.xlPasteValues); //--</ copy >--
//-< save >- string sFilename_New=active_Workbook.Path + "\\" + "Retouren_Daten"; new_Workbook.SaveAs(sFilename_New); //-</ save >-
//< end > new_Workbook.Close(); //</ end > //------------</ export_Sheet1() >------------ }
|
Solution:
Because of the formulas you have to set the country specific language.
Excel uses English by default. When copying via vba, c # the specification is not given
Wrong solution:
Setting via Application-> Assembly-> Neutral language
Wrong solution on the internet:
Solution according to internet
set Application.Visible = true and Application.WindowState = xlWindowState.xlMinimized
The error code 0x800A03EC (-2146827284) means NAME_NOT_FOUND
public void export_Sheet1() { //------------< export_Sheet1() >------------ //< init > Application excel_App =Globals.ThisAddIn.Application; Workbook active_Workbook = Globals.ThisAddIn.Application.ActiveWorkbook; Worksheet active_Worksheet = active_Workbook.Worksheets[1]; //</ init >
//< new > Application new_excel_App = Globals.ThisAddIn.Application; new_excel_App.Visible = false; //*solves: 0x800A03EC new_excel_App.WindowState = XlWindowState.xlMinimized; //*solves: 0x800A03EC Workbook new_Workbook = new_excel_App.Workbooks.Add(); Worksheet new_Worksheet = new_Workbook.Worksheets[1]; //< new >
//--< copy >-- active_Worksheet.UsedRange.Copy(); new_Worksheet.Cells[1, 1].Select(); //#ok new_Worksheet.Paste(); //*works //#Error: new_Worksheet.PasteSpecial(XlPasteType.xlPasteValues, XlPasteSpecialOperation.xlPasteSpecialOperationNone, false, false); new_Worksheet.PasteSpecial(Format:XlPasteType.xlPasteValues,Link:false); //->ERROR !!
//--</ copy >--
//-< save >- string sFilename_New =active_Workbook.Path + "\\" + "Retouren_Daten"; new_Workbook.SaveAs(sFilename_New); //-</ save >-
//< end > new_Workbook.Close(); new_excel_App.Quit(); //*solves: 0x800A03EC //</ end > //------------</ export_Sheet1() >------------ }
|
Wrong solution
System.Runtime.InteropServices.COMException HResult=0x800A03EC Message=Ausnahme von HRESULT: 0x800A03EC Source=<Cannot evaluate the exception source> StackTrace: <Cannot evaluate the exception stack trace>
|
Wrong solution from the internet
//*using System.Globalization; //CultureInfo current_Culture = CultureInfo.CurrentUICulture; //typeof(Excel.Range).InvokeMember("Formula", // System.Reflection.BindingFlags.Public | // System.Reflection.BindingFlags.Instance | // System.Reflection.BindingFlags.SetProperty, // null, range1, // new object[] { "=SUM(10,20)" }, // System.Globalization.CultureInfo.GetCultureInfo(1033));
|
Wrong solution from the internet
new_Worksheet.Cells[1, 1].Select(); //#ok new_Worksheet.Paste(); //*works //#Error: new_Worksheet.PasteSpecial(XlPasteType.xlPasteValues, XlPasteSpecialOperation.xlPasteSpecialOperationNone, false, false); //new_Worksheet.PasteSpecial(Format:XlPasteType.xlPasteValues,Link:false);
|
Wrong solution
Allegedly, the solution would be to run the application minimized
Application new_excel_App = Globals.ThisAddIn.Application; new_excel_App.Visible = false; //*solves: 0x800A03EC new_excel_App.WindowState = XlWindowState.xlMinimized; //*solves: 0x800A03EC
|