open word doc with excel 2016 button on mac

[亡魂溺海] 提交于 2019-12-13 05:17:51

问题


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:


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



来源:https://stackoverflow.com/questions/52620644/open-word-doc-with-excel-2016-button-on-mac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!