问题描述
在执行"STOPS HERE"注释之前的语句后,此Word VBA代码停止.
This Word VBA code stops after executing the statement before the 'STOPS HERE' comment.
Public Sub Test_Main()
' Open the Word file
Dim sourceDocPath As String
sourceDocPath = ThisDocument.Path & "\TestDoc.docx"
Dim sourceDoc As Document
Set sourceDoc = Documents.Open(sourceDocPath, ReadOnly:=True)
' !!!! STOPS HERE !!!!
MsgBox "GOOOOOOOOOOOOOOOOOOOOOAAAAAAAAAAAALLLL!!!"
Set sourceDoc = Nothing
End
End Sub
•指定的Word文件由停止点之前的语句打开.
•没有错误消息.打开文件后,它就停止了.
•从Word宏的自己的"Document_Open"运行时,"Test_Main"将正常运行到最后.直接从开发人员>宏"运行时,它将停止.
•设置对象=无"不能解决问题.
•"End"语句不能解决问题.
•请直接将"TestDoc.docx"与测试Word宏放在相同的位置.它可以为空.
•环境为Office 365& Windows 10 64位.
• The specified Word file opens by the statement before the stop point.
• There's no error messages. It just stops after opening the file.
• When run from its own "Document_Open" of the Word macro, the "Test_Main" runs ok to the end. It stops when run directly from "Developer > Macros".
• "Set object = nothing" didn't solve the problem.
• "End" statement didn't solve the problem.
• Please place "TestDoc.docx" in the same directly as the test Word macro. It can be empty.
• The environment is Office 365 & Windows 10 64 bit.
如果有人遇到过类似的问题或知道如何解决该问题,请告诉我!
If anyone has experienced the same kind of problems or knows how to solve the problem, please let me know!
推荐答案
根据本文,这似乎是Word版本1807(内部版本10325.20082)的错误.我们可能需要降级Word以避免此问题.
According to this article, this seems to be a bug of Word Version 1807 (Build 10325.20082). We may need to downgrade Word to avoid this problem.
解决方法:据我测试,从自己的"Document_Open"运行时,代码可以正常运行而不会停止.
Workaround:As far as I tested, somehow the code runs ok without stopping when run from its own "Document_Open".
进度:我在2018/08/20注意到,该问题现在无法重现.自出现此问题以来,我的Word版本没有更改,即版本1807(内部版本10325.20082).
Progress:I noticed on 2018/08/20 that somehow the problem doesn't reproduce now. The version of my Word has not been changed since I had this problem, which is Version 1807 (Build 10325.20082).
这篇关于在Documents.Open之后VBA代码停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!