简体   繁体   English

Word 2013 VBA-打开文档中止宏

[英]Word 2013 VBA - opening document aborts macro

I'm running pretty simple VBA in Word: 我在Word中运行非常简单的VBA:

Sub Something

On Error GoTo prob

Dim d As Document

Set d = Documents.Open(FileName:="c:\ajb files\test.docx")

'this should run if macro succeeds
MsgBox "ok"
Exit Sub

'this should run if macro fails
prob:
MsgBox "prob"

End Sub

This macro opens the Word document then stops (without triggering an error message). 此宏打开Word文档,然后停止(不触发错误消息)。

I tried running the same macro in Word 2010 and it works fine. 我尝试在Word 2010中运行相同的宏,但效果很好。 I haven't got an Acer laptop, or any weird anti-virus or other software running. 我没有Acer笔记本电脑,也没有任何奇怪的防病毒软件或其他软件在运行。 I removed all Word add-ins, and the problem still happens. 我删除了所有Word加载项,但问题仍然存在。

If I go straight into Word and run this macro, it works fine. 如果我直接进入Word并运行此宏,它将正常工作。 The problem comes when I first run a macro in Access which tries to run this code through Word VBA, and seizes up on the line above. 当我第一次在Access中运行一个试图通过Word VBA运行此代码并抓住上面的代码的宏时,就会出现问题。 If I then try to run the macro without first closing Word, it hangs after opening the document. 如果然后我尝试运行宏而不先关闭Word,则在打开文档后它会挂起。

OK, I've solved the problem. 好,我已经解决了问题。 The Access VBA macro was opening a Word template which wasn't in a trusted location. Access VBA宏正在打开Word模板,该模板不在受信任的位置。 Somewhere along the line this was causing it to hang. 沿线的某个地方导致它挂起。 I've added the Word template folder to my list of trusted locations and it seems to have solved the problem. 我已将Word模板文件夹添加到我的受信任位置列表中,似乎已经解决了该问题。

Check out this thread: VBA code stops after Documents.Open 签出此线程: Documents.Open之后VBA代码停止

I have the exact same problem and I thought I found a fix today when I set the windows security for the folder holding the file allow anything and everything to edit the folder. 我有完全相同的问题,当我为包含文件的文件夹设置Windows安全性时,我想今天找到了一个修复程序,该文件允许所有内容编辑该文件夹。 (The location was already trusted in Word). (该位置已被Word信任)。 It solved the problem in ONE location, but the exact same fix, plus making sure the location was trusted, did NOT work in two other places. 它解决了一个位置的问题,但是完全相同的解决方案,以及确保该位置受信任,在其他两个地方均无效。

I am going to try rolling back my Word version per the instructions in the thread I linked. 我将尝试根据链接的线程中的说明回滚我的Word版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM