open word doc with excel 2016 button on mac

2019-08-27 10:30发布

I am trying to use this code with a button to open a word doc in excel 2106 on a mac running high sierra:

Sub buttontest1()
Dim objdoc As Object

FileName = "/Volumes/256SSD/word docs/shortcut keys.docx"

With CreateObject("word.application")

Set objdoc = .documents.open(FileName)
End With

Set objdoc = Nothing
End Sub

The first time I run this, it works fine. I then close the word doc (command q) and run it again but I get a runtime error -2146959355 (80080005) and a blank word doc opens. I click "End" in the runtime error box and quit the word doc and run the code again and the word doc opens correctly. I quit the doc and run again and get the run time error.

Can someone help please?

PS I have tried using : instead of / in the file path but that gives a different error

1条回答
家丑人穷心不美
2楼-- · 2019-08-27 10:54

I can reproduce the behaviour. This appears to be a known issue with Mac VBA - since more than a year, as confirmed by Microsoft:

https://answers.microsoft.com/en-us/msoffice/forum/msoffice_officeinsider-mso_mac-msoinsider_excel/trying-to-open-word-from-excel-vba-results-in-run/856d9a54-cc92-4ad8-9f49-cae38e7335b7

查看更多
登录 后发表回答