VBA 代码在 Documents.Open 后停止 [英] VBA code stops after Documents.Open

查看:52
本文介绍了VBA 代码在 Documents.Open 后停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此 Word VBA 代码在执行 'STOPS HERE' 注释之前的语句后停止.

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"运行到最后.直接从开发人员 > 宏"运行时会停止.
• Set object = nothing"没有解决问题.
• 结束"语句没有解决问题.
• 请直接将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 (Build 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.

https://answers.microsoft.com/en-us/msoffice/forum/msoffice_word-msoffice_custom-mso_280225-mso_810225-causing-vba-problems-with/538e8c3c-355e-47a7-9e3f-58cf04902c10?tm=1533213042907

解决方法:就我测试而言,代码在从其自己的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).

这篇关于VBA 代码在 Documents.Open 后停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆