Excel crash after opening it into vb.net using introp

1

Excel crash after opening it into vb.net using introp

Followig is my code which i used for importing the data from excel

    Dim misValue As System.Reflection.Missing
    Dim tbl As New System.Data.DataTable
    Dim xlApp As nExcel.Application
    Dim xlWorkBook As nExcel.Workbook
    Dim xlWorkSheet As nExcel.Worksheet

    xlApp = New nExcel.Application
    Try
        xlWorkbook = xlApp.Workbooks.Open(sFilePath)


        Dim issheetext As Boolean
        Dim sheet As nExcel.Worksheet
        For Each sheet In xlWorkbook.Sheets
            If sheet.Name.Equals(sSheetname) Then
                issheetext = True
                Exit For
            End If
        Next
        If issheetext Then
            xlWorkSheet = DirectCast(xlWorkbook.Sheets(sSheetname), nExcel.Worksheet)

            ' get range object
            Dim myRange As nExcel.Range = DirectCast(xlWorkSheet.get_Range("A1:BZ102451"), nExcel.Range)

            For i As Integer = 0 To myRange.Columns.Count
                Dim cellval As Object
                cellval = DirectCast(myRange.Cells(1, i + 1), Object)
                tbl.Columns.Add(cellval.ToString(), cellval.GetType())
            Next
            For i As Integer = 0 To myRange.Rows.Count - 2
                tbl.Rows.Add()

                For j As Integer = 0 To myRange.Columns.Count - 1
                    Dim CellValue As Object = DirectCast(myRange.Cells(2 + i, j + 1).Value2, Object)
                    tbl.Rows(i)(j) = CellValue
                Next
            Next
        End If
    Catch ex As Exception
    Finally
        Try
            releaseObject(xlWorkSheet)
            releaseObject(xlWorkbook)
            releaseObject(xlApp)
        Catch
        End Try


    End Try

    Return tbl

but when debugger cross xlWorkbook = xlApp.Workbooks.Open(sFilePath)

its shows me

Excel Crash Report

and in exception it shows me

The remote procedure call failed. (Exception from HRESULT: 0x800706BE)

Thanks in Advance

excel
vb.net
asked on Stack Overflow Feb 15, 2017 by Tanmay Nehete • edited Jun 20, 2020 by Community

1 Answer

0

Couple of things based on your code I believe your code is correct:

  • Please verify file path sFilePath
  • Any background popup blocking Excel to launch
  • Kill all excel from Task Manager and Restart your computer
  • In Window Run type Excel -r and hit Enter key (it will reset Excel to default)
answered on Stack Overflow Jun 15, 2020 by Rashid Khan

User contributions licensed under CC BY-SA 3.0