从Excel打开Word文档(Office 2016和MacOS)

问题描述 投票:3回答:2

我正在尝试通过VBA从Excel打开Word文档。我得到

运行时错误2146959355(80080005)

我需要将数据从Excel复制到Word,但是系统无法打开Word文档。

我的代码的一部分:

Dim ws As Worksheet, msWord As Object

Set ws = ActiveSheet
Set msWord = CreateObject("Word.Application")

With msWord
    .Visible = True
    .Documents.Open ThisWorkbook.Path & "~/Desktop/! Rezervační smlouva - vzor.docx"
    .Activate
excel vba excel-vba-mac
2个回答
4
投票

您可能会收到此错误,因为

  1. MAC不支持/作为路径分隔符。它使用:作为路径分隔符。

enter image description here

  1. 您的MS Office没有最新更新。

在EXCEL 2011中经过测试的方法

Sub Sample()
    Dim oWord As Object

    Set oWord = CreateObject("Word.Application")

    oWord.Visible = True

    Ret = Application.GetOpenFilename()

    oWord.documents.Open (Ret)
End Sub

enter image description here


0
投票

代码:

Dim oWord作为对象

Set oWord = CreateObject("Word.Application")

oWord.Visible = True

Ret = Application.GetOpenFilename()

oWord.documents.Open (Ret)
© www.soinside.com 2019 - 2024. All rights reserved.