每当我打开文档时,VBA代码都会停止

编程入门 行业动态 更新时间:2024-10-10 21:22:44
本文介绍了每当我打开文档时,VBA代码都会停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

首先很抱歉发布此消息,我知道它可能与此重复

First of all sorry for posting this, I know it's probably duplicated from this post, I tried to post it as an edit but it got rejected and I can't comment because I don't have 50 reputation, also this is not a proper answer. Hope this helps to get a better understanding of the problem and more attention.

我在一家使用VBA的公司工作,我们使用Documents.Open很长时间了,直到现在,它从未给我带来任何问题.该问题似乎是随机的,因为没有很多客户端有此问题,但是现在主要与Office 365变得更加一致.也许是由于实现的原因?

I work in a company that uses VBA and we've been using Documents.Open for a long time and it never gave me any problems, until now. The problem seems rather random, as not many clients have this, but it's turning more consistent now mainly with Office 365. Maybe it's due to an actualization?

每当我执行Documents.Open时,被请求的文档都会打开,但是之后的所有内容都不会执行.它可以很简单:

Whenever I do Documents.Open the requested document will open, but anything that comes after that won't be executed. It can be as simple as:

Sub Test() Documents.Open(filename) MsgBox "Hi" End Sub

该消息框将永远不会显示.我也尝试过此方法,因为我在其他论坛中发现了一些相关问题:

And the message box will never be shown. I've also tried this, as I found something related in other forums:

Sub Test() Dim doc as Document set doc = Documents.Open(filename) MsgBox "Hi" End Sub

我什至尝试了旧版的WordBasic.FileOpen().没有任何帮助,打开文档后代码停止执行.经过无奈的尝试,我创建了一个COM dll,它打开了一个文档,在dll完成后,在dll和VBA中都带有一个消息框. dll可以正常运行,但是一旦回到VBA,代码就会停止并且不显示消息框.

I've even tried the old open WordBasic.FileOpen(). Nothing helps, code stops executing after opening the document. In a desperated attempt at making this work, I've created a COM dll that opens a document, with a message box in the dll and in VBA after the dll has done it's part. The dll functions properly but as soon as it gets back to VBA the code stops and it doesn't show the message box.

我已经进行了一些研究,并且与已知的 shift-关键错误,因为我可以通过按播放"按钮来运行示例代码,因此在打开文档时无需按任何键.

I've done some research and it has nothing to do with the known shift-key bug since I can run the example code by pressing the play button, so no keys are being pressed when the document opens.

然后,我尝试使用AutoOpen事件,如其他文章所示通过调试,我意识到在有问题的计算机中从未调用过PseudoAutoOpen事件.

Then I tried to work with the AutoOpen event as seen in this other post and by debbuging I've realized that the PseudoAutoOpen event it's never called in the computers with the problem.

还要确保所有内容都位于受信任文档的位置,并且已启用宏,如另一篇文章所述: Word 2013 VBA-打开文档会中止宏

Also made sure that everything it's in the trusted documents location and that the macros are enabled, as this other post said: Word 2013 VBA - opening document aborts macro

更新

我在调试时偶然发现,如果我两次运行示例宏,第二次(打开目标文档)将按预期运行.

I've found out accidentally while debugging, that if I run the example macro twice, the second time (with the targeted document opened) it works as intended.

我开始对此失去理智.

推荐答案

问题似乎与1807 Build 10325.20082更新有关.

The problem seems to be with the 1807 Build 10325.20082 update.

还原到较早的版本(9330.2087)为我解决了这个问题:

Restoring to an earlier build (9330.2087) fixed the problem for me:

support.microsoft/en-us/help/2770432/how-to-revert-to-an-earlier-version-of-office-2013-or或-office-2016-clic

更多推荐

每当我打开文档时,VBA代码都会停止

本文发布于:2023-11-27 15:29:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638568.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:都会   当我   代码   文档   VBA

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!