简体   繁体   English

单词2013年VBA /宏崩溃

[英]word 2013 VBA / Macro crashes

Word 2013 crashes when running a VBA/macro on a document that has comments section enabled. 在启用了注释部分的文档上运行VBA /宏时,Word 2013崩溃。 The macro searches for a character and replaces it with "" (blank) in the comments section and main document. 宏搜索一个字符并用注释部分和主文档中的“”(空白)替换它。 This is done using Selection.Find.Execute API. 这是使用Selection.Find.Execute API完成的。 When there is no comments section or no mark up is selected, Word doesn't crash. 当没有评论部分或没有选择标记时,Word不会崩溃。

This is on Windows 10 and word 2013. The macro works well in Word 2007 and Windows 7. 这是在Windows 10和word 2013.该宏在Word 2007和Windows 7中运行良好。

Reproducible steps: 可重复的步骤:

  1. Create a simple document with one text and add comment. 使用一个文本创建一个简单文档并添加注释。

  2. Insert the sample comment text as below: (add vertically like: A : & (enter) and so on) 插入示例注释文本如下:(垂直添加如下:A:&(输入)等)

     A: & B: & C: & D: & E: & F: & G: & H: & I: & J: & K: & L: & M: & N: & 
  3. Create macro: 创建宏:

     Sub Test_Macro() ActiveWindow.View.SplitSpecial = wdPaneComments With Selection.Find .Text = "&" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.HomeKey unit:=wdStory If Selection.Find.Execute = True Then 'We found the slash. Delete it. Selection.TypeBackspace End If End Sub 
  4. Execute the Macro ( & will be cleared). 执行宏( &将被清除)。 Keep on executing again; 继续执行; Word will crash 2-3 times out of 10. (update the comment text accordingly, when all & s are cleared). Word将在10次中崩溃2-3次。(相应地更新注释文本,当清除所有& s时)。

I do not see a question in your text, so I can not answer, but I can confirm that Microsoft Word 2013 crashes on ActiveDocument.Content.Find.Execute . 我没有在您的文本中看到问题,因此我无法回答,但我可以确认Microsoft Word 2013在ActiveDocument.Content.Find.Execute崩溃。 I routinely had to work around this by manually exercising the Replace dialog before executing the macro. 我通常不得不通过在执行宏之前手动执行“替换”对话框来解决此问题。 This worked (almost) every time. 这几乎每次都有效。 Now I found this post that says that it has something to do with Execute running with an empty undo record. 现在我发现这篇帖子说它与使用空的撤销记录运行的Execute有关。 I was able to work around this issue by inserting a line of code that adds some text to the last paragraph of the document right after the undo record is created. 我能够通过插入一行代码来解决这个问题,该代码行在创建撤销记录后立即将一些文本添加到文档的最后一段。

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

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