My code needs to enable spelling check in MS Word 2010 so user can see red underlines under misspellings.
In current version I try to do this to enable spelling check:
wordApplication.Options.CheckSpellingAsYouType = true;
wordApplication.Options.SuggestSpellingCorrections = true;
wordApplication.ActiveDocument.ShowSpellingErrors = true;
wordApplication.ActiveDocument.CheckSpelling();
I open Word and type in "Test texxt string". After this I run my code but nothing happens:
I don't see any underlines under "texxt". If I go to options I see that "check spelling as you type" option was enabled:
Now if I check this property:
wordApplication.ActiveDocument.SpellingErrors[0].Text
It will contain "texxt" which means that spelling was actually checked.
Also if I simply restart MS Word and type in same text - red underlines become visible:
I also tried to call Application.ScreenRefresh and set ScreenUpdating properties but this haven't given any effect.
Note: I run this code/macro in the beginning, when there is no text in a document. If some text is there - it works.
Note2: Exact steps to reproduce:
Start MS Word. Go to options and disable "check spelling as you type". Restart Word.
Start Word and run following macro:
Options.CheckSpellingAsYouType = true Options.SuggestSpellingCorrections = true ActiveDocument.ShowSpellingErrors = true
Type in following text: "Test texxt string.". Press Enter.
Run following macro
MsgBox ActiveDocument.SpellingErrors(1).Text
You will see "texxt" in MessageBox but not red underlines
CheckSpellings
call so will not affect the display.