簡體   English   中英

使用vba Mac打開單詞-OS X

[英]Open word using vba Mac - OS X

我正在嘗試在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文件?

有人可以幫幫我嗎?

這對您有用嗎?

sub Test()

dim objdoc as object

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

end sub

安全地從文件中打開Word文檔的代碼。 處理您已經打開單詞的情況。

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")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM