Excel Interop Error

Dewayne Basnett 1,116 Reputation points
2023-03-15T13:30:04.3066667+00:00

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.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,415 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,581 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.
3,532 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Dewayne Basnett 1,116 Reputation points
    2023-03-16T14:08:57.3166667+00:00

    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.Activate()
    
            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.

    0 comments No comments

  2. Dewayne Basnett 1,116 Reputation points
    2023-03-16T15:49:32.9066667+00:00

    FIXED

    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

    0 comments No comments