none
Exception arises when copying an excel worksheet from one workbook to another programmatically RRS feed

  • General discussion

  • I am developing an excel com add-in. As per our requirement I am copying an excel worksheet from one source workbook to destination workbook programmatically. But when copy method of excel sheet invoked an exception arises
    my code:

    Excel.Worksheet sheet = sourceWB.Worksheet.get_item(1) as Excel.Worksheet;

    sheet.Copy(Type.Missing, myWorkbook.Worksheets[1]);

    when this piece of code executed this exception arises

    Managed Debugging Assistant 'FatalExecutionEngineError' has detected a problem in 'C:\Program Files\Microsoft Office\Office15\excel.exe'.

    Additional information: The runtime has encountered a fatal error. The address of the error was at 0x465f2334, on thread 0x1c90. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.


    Manas Mangal Pattanaik Sr. Software Engineer, Andolasoft india pvt Ltd.

    Monday, November 9, 2015 1:50 PM

All replies

  • try syntax like this:

       Dim wb As Excel.Workbook
       Set wb = Workbooks("DesinationWorkbook.xlsx")
       sourceWB.Sheets(1).Copy after:=wb.Sheets(1)
       MsgBox "done"



    Warm Regards, Crystal http://www.AccessMVP.com/strive4peace * (: have an awesome day :)

    Tuesday, November 10, 2015 8:27 AM