2

I am trying to disable spell checking in the currently active Word document using a VSTO add-in. I want to avoid saving the spelling errors in the document's Open XML markup.

I tried to use the Range.NoProofing property.

currentDocument.Content.NoProofing = 1; 

The MSDN documentation states that this should be set to true, however, the property's type is int. I tried setting it to 1, but it doesn't work (spell checking errors still appear in the document). In the debugger I see that the property is still set to 0 after the assignment.

How to properly use the Range.NoProofing property or is there any other way to disable spell checking in a Word document?

2 Answers 2

2

I ended up ignoring all spelling errors before saving the document using the DocumentBeforeSave event.

this.application.DocumentBeforeSave += this.OnDocumentBeforeSave; 

The NoProofing property seems to work properly when used on ranges which contain spelling errors.

private void OnDocumentBeforeSave(Document doc, ref bool saveAsUi, ref bool cancel) { // Ignore all spelling errors in the document foreach (Range error in this.application.ActiveDocument.SpellingErrors) { error.NoProofing = 1; } // Ignore all spelling errors in content controls foreach (ContentControl control in this.application.ActiveDocument.ContentControls) { control.Range.NoProofing = 1; } } 
Sign up to request clarification or add additional context in comments.

Comments

0

I've always used -1 to be true in VSTO and in a few places it seems to matter compared to using 1 for true.

I needed to disable spell check on all endnotes. The answer of using NoProofing worked, but I later found an easier way to change the "Endnote Text" style to add NoProofing as -1.

In my code this is:

wordDocument.Styles[Word.WdBuiltinStyle.wdStyleEndnoteText].NoProofing = -1; 

This can be done with other styles as well.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.