Excel 2016 crashed by showing message 'Microsoft Excel had stopped working' when integrated in a .Net application RRS feed

  • Question

  • Hello All,

    This is sampath i had a issue in excel 2016 when embedded in vb .net code,below is my explanation in detail.

    I developed an application in vb .net where excel(.xlsm file) is placed inside the panel for editing purpose it was working fine with excel 2007 but when i moved to excel 2016 the excel is crashing every time when we open the application and edit in excel.Please help me in this regard.

    Below is my code when is used for integration


    Imports System.Runtime.InteropServices
    Imports Excel = Microsoft.Office.Interop.Excel
    Public Class Form1
        Public hwnd1 As IntPtr
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim excApp As New Excel.Application()
            excApp.Visible = True
            Dim wb As Excel.Workbook = excApp.Workbooks.Open("C:\tee_a1glbl1-XL.xlsm")
            hwnd1 = CType(excApp.Hwnd, IntPtr)

            SetParent(hwnd1, Me.Handle)
            MoveWindow(hwnd1, 0, 0, 100, 100, True)
        End Sub

        <DllImport("user32.dll")> _
        Public Shared Function SetParent(hWndChild As IntPtr, hWndNewParent As IntPtr) As IntPtr
        End Function

        <DllImport("user32.dll")> _
        Public Shared Function MoveWindow(hwnd As IntPtr, x As Integer, y As Integer, nWidth As Integer, nheight As Integer, repaint As Boolean) As Boolean
        End Function
    End Class


    Hoping for a quick reply

    Thanks & Regards,


    Friday, January 13, 2017 5:48 AM

All replies

  • Hi Sampath,

    This forum  mainly focus on general questions and feedback related to Excel client. Since your issue is more related to developing issues involving Excel, I would move this thread into the following dedicated MSDN forum for Excel:

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us.

    Thank you for your understanding.

    Best regards,
    Yuki Sun

    Please remember to mark the replies as answers if they helped.

    If you have feedback for TechNet Subscriber Support, contact

    Monday, January 16, 2017 5:48 AM
  • Hi,

    I could reproduce your issue if I don’t release the object.

    I suggest you quit the Excel or release application object after using.



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Tuesday, January 17, 2017 8:40 AM