Excel Interop Error

Dewayne Basnett 606 Reputation points

Over the years I have used this pattern to create a new Excel document,

        Dim objApp As Excel.Application
        Dim objBook As Excel.Workbook
        Dim objSheet As Excel.Worksheet

        objApp = New Excel.Application
        objBook = objApp.Workbooks.Add()
        objSheet = CType(objBook.Sheets(1), Excel.Worksheet)

On this line I get the error shown,

    objBook = objApp.Workbooks.Add() ' <<<   {"The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))"}

I went back to some applications that I've had for years with the same pattern and they also fail, both in Visual Studio and in the published/installed version.

Microsoft Technologies based on the .NET software framework.
912 questions
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
1,983 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
2,214 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Dewayne Basnett 606 Reputation points

    I also tried it this way

    Option Strict Off
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim xl As Object
            Dim xlWorkBooks As Object
            Dim xlWorkBook As Object
            Dim xlWorksheet As Object
            xl = CreateObject("Excel.Application")
            xl.DisplayAlerts = False
            xl.Visible = True
            xlWorkBooks = xl.Workbooks
            'The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))
            xlWorkBook = xl.Workbooks.Add() '  same error here
            xlWorksheet = xl.Sheets(1)
            xlWorksheet.Cells(1, 2).Value = "XX"
        End Sub
    End Class

    with the same result. In both cases Excel starts and the workbook seem to be created.

  2. Dewayne Basnett 606 Reputation points


    What fixed this was to disable the Microsoft Teams add ins. There's a day chasing my tail.

    Can't mark my own answer as the accepted answer. Hmmmm