(Solved) – Word for Mac – Error while calling Excel.Application.Workbooks.Open runtime error -2146959355 (80080005)

(solved)-–-word-for-mac-–-error-while-calling-excelapplicationworkbooks.open-runtime-error-2146959355-(80080005)

I am trying to open an Excel file in Word to read the values of some cells and do some magic to a new file in word.

A thing that I did many times using Microsoft Windows. Now that I’m unable to use Windows and I have to use my private computer I am facing some issues to use the files that I wrote on my Mac.

I am using the same version on both O.Ss.: Office Word 2016 but I am getting an error when I run the macro in my mac.

I am getting a

Runtime-Error with code -2146959355 (80080005).

The code is huge but I tried stripping down to find the error. Needless to say that I’ve reached the point that stripping more is equals to removing the macro. So, this is the code that is giving me the error. And I can’t understand the reason.

Sub AutoOpen()

    Dim objExcel As New Excel.Application
    Dim exWb As Excel.Workbook
    Dim excelFile As String
    excelFile = ActiveDocument.Path & Application.PathSeparator & "file.xlsx"

    If (Dir(excelFile) <> "") Then
        Set exWb = objExcel.Workbooks.Open(excelFile)
        exWb.Close
    Else
        MsgBox ("File not found")
    End If
End Sub

The error is referring to the Set of exWb

This same code is working in Windows

Leave a Reply

Your email address will not be published. Required fields are marked *