Word for Mac - 调用 Excel.Application.Workbooks.Open 时出错 -2146959355 (80080005) [英] Word for Mac - Error while calling Excel.Application.Workbooks.Open runtime error -2146959355 (80080005)

查看:363
本文介绍了Word for Mac - 调用 Excel.Application.Workbooks.Open 时出错 -2146959355 (80080005)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Word 中打开一个 Excel 文件以读取某些单元格的值并对 Word 中的新文件执行一些魔术.

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.

我使用 Microsoft Windows 做过很多次的事情.现在我无法使用 Windows 并且必须使用我的私人计算机,我在使用我在 Mac 上编写的文件时遇到了一些问题.

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.

我在两个操作系统上使用相同的版本:Office Word 2016,但在 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.

我得到一个

运行时错误,代码为 -2146959355 (80080005).

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

错误是指exWb

同样的代码在 Windows 中也能运行

This same code is working in Windows

推荐答案

问题是在 Mac 上,通过 New 或 CreateObject 创建新的 COM 对象目前已被破坏.或者至少,对于一些新安装 Mac OS 和 Office 的用户来说,它是坏的.

The problem is that on Mac, creating new COM objects via New or CreateObject is currently broken. Or at least, it is broken for some users with fresh installations of Mac OS and Office.

如果你能把你的代码再固定一点,我想你会看到这个错误发生在Dim objExcel As New Excel.Application"之后的第一个可执行行中.

If you can pin your code down a little more, I think you will see that this error occurs in the first executable line after "Dim objExcel As New Excel.Application".

多年来,这个问题已经多次报告给微软,但一直没有明显的回应.我的猜测是他们的 dev.团队对他们的 Mac OS 配置进行了历史性的更改,他们忘记了这意味着他们不会遇到这个问题,或者在 Mac 上使用 COM 的专业人士已经离开,微软正在拖延,直到他们能够恢复一些相关的专业知识.

This problem has been reported to Microsoft on several occasions over several years, but there has been no obvious response. My guess is that either their dev. team has made historic changes to their Mac OS configuration that they have forgotten about that means they don't encounter this problem, or that the people who had expertise in working with COM on Mac have left and Microsoft is stalling until they can recover some relevant expertise.

似乎没有任何明显的 Microsoft 文档说明它.

There does not really seem to be any obvious Microsoft documentation about it.

更新.

在 Mac Word 16.34 版中,情况似乎有所改变.

In v. 16.34 of Mac Word, things seem to have changed a bit.

GetObject 还是没用.

GetObject is still useless.

但是如果你这样做了

Dim app as Object
Set app = CreateObject("Excel.Application")

应用不再是Nothing.不幸的是,如果你这样做

app is no longer Nothing. Unfortunately, if you do

typename(app)

typename(app)

你得到WorkBook",这意味着代码仍然没有返回正确类型的对象.

you get "WorkBook" which means that the code is still not returning the right kind of object.

但在这里,我至少现在可以做类似的事情

But here, I can at least now do something like

If UCase(Typename(app)) = "WORKBOOK" Then
  Set app = App.Application
End If

这篇关于Word for Mac - 调用 Excel.Application.Workbooks.Open 时出错 -2146959355 (80080005)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆