使用vba Mac - OS X打开单词

时间:2016-11-26 01:34:30

标签: macos vba excel-vba excel

我试图在Mac OS X上自动打开excel文档,但它不起作用。我的代码是:

Sub Button81_Click()
    Dim objWord
    Dim objDoc
    Set objWord = CreateObject("Word.Application")
    Set objDoc = objWord.Documents.Open("/Users/ricardo/Miniman/miniman_uti.docx")
    objWord.Visible = True
End Sub

路径会错吗?对于这条道路" /Users/ricardo/Miniman/miniman_uti.docx"它打开excel文件。为什么不用word文件?

有人可以帮帮我吗?

2 个答案:

答案 0 :(得分:0)

这对你有用吗?

sub Test()

dim objdoc as object

with CreateObject("word.application")
set objdoc = .documents.open("path")
end with

end sub

答案 1 :(得分:0)

从文件中安全打开word doc的代码。 处理已打开单词的情况。

Dim w As Object
' If word is already open get ahold of the running instance
' Otherwise create a new instance
On Error Resume Next
Set w = GetObject(, "Word.Application")
If w Is Nothing Then Set w = CreateObject("Word.Application")
On Error GoTo 0
' Close all open files and shutdown Word
' Loop through any open documents and close them
Do Until w.Documents.Count = 0
    w.Documents(1).Close
Loop
w.Quit False
Set w = Nothing

' Now that all instances of word are closed, open the template
Dim wdApp As Object
Dim wdDoc As Object
Set wdApp = CreateObject("Word.application")
wdApp.Visible = True
wdApp.DisplayAlerts = False
Set wdDoc = wdApp.Documents.Open(Filename:="MYPATH")
相关问题