Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Solved: 0x800A03EC at Excel Pastespecial

03.11.2018 (πŸ‘15629)


 

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, falsefalse);

//--</ 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, falsefalse);

    //--</ 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