开发者

Reset Ignored Spellcheck Words in VSTO for Word 2010

In older versions of Wo开发者_运维技巧rd, you could do the following to reset the words that a user had chosen to ignore:

Application.ResetIgnoreAll();
ActiveDocument.SpellingChecked = false;
ActiveDocument.CheckSpelling();

I'm trying this same function in VSTO for Word 2010 and while it rechecks words that were 'Ignore Once'd, it won't recheck words that were 'Ignore All'd. I've tried recording a macro while going to Options->Proofing and clicking on 'Recheck Document,' and while that does reset the Ignore All list correctly, the macro it generates is the same as the code above.

Does anyone know if this is a bug in Word 2010/VSTO, or if there is a different way to reset the 'Ignore All' list?


This is a bug, but there is a workaround in VBA, which you may be able to adapt for VSTO. As you correctly identified, the ActiveDocument.SpellingChecked is broken in the Word Object Model, but in Backstage view under Options|Proofing the Recheck Document button works correctly. Although the macro recorder will not reveal the commands to do so, one can use a combination of a Word built-in macro and SendKeys to navigate to the button "manually" to execute the command:

Application.Run MacroName:="FileNewDialog" 'Access Backstage view
SendKeys "%TP" 'Options|Proofing
SendKeys "%K" 'Recheck Document button
SendKeys "%Y" 'Yes button for confirmation message box
SendKeys "{ENTER}", True 'Exit the dialog box
SendKeys "{F7}" 'Perform spell check

Because SendKeys places Word into a sort of manual mode, the program often will ignore programmatic commands upon exiting the Backstage view. This is the reason the above code uses the F7 keystroke to perform the spell check instead of ActiveDocument.CheckSpelling.

Important note about testing SendKeys: SendKeys cannot be tested by stepping through the code in the VBA IDE as the keystrokes it sends out when running are sent to the active window at the time of execution (which would be the VBA development window). To test SendKeys, save the macro and attach it to a QAT button, which can be depressed, as needed, for testing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜