1
votes

VBA Noob here. I take my python programming notes in a word document since I can import images into it and align/format text quickly. Any code pasted into this document comes up as a spelling error. I'm trying to find a way to ignore spelling errors within a selected text area so I don't have to deal with ignoring each spelling error line of code individually. I don't want to turn off spell check in the document.

Ideally, I'd able to write a macro that read:

Selection.ShowSpellingErrors = True 

but ShowSpellingErrors() can only be used with ActiveDocument. I was able to a record a macro that ignored spelling errors with:

Selection.LanguageID = wdEnglishUS 
Selection.NoProofing = True

However, any new text I type into this also doesn't get proofed, which is something I don't want. I want to be able to write new text and see any errors I make. Thanks for any help!

1
Since you're selecting the no-proofing sections manually, is there a reason why you want to set the no-proofing by code instead of Word's menu?A.S.H
@A.S.H, because I'm not always selecting small no-proofing areas manually. Sometimes I'm copy and pasting pages of R console output and graphics then continuing to add my own notes. I'm essentially trying to loop through a large amount of text and ignore each spelling error one time.Geoff

1 Answers

0
votes

Not a VBA Macro, but I think this answer may be relevant to your problem anyway.

Try creating a style for code which does not include spell check. Anything with this style does not get spell checked, while the rest of the document does. Sometimes I find the code shows the red underline, but if you run spell check it should just disappear without needing to be 'fixed'.

Create a new style, in the modify formatting dialog, go to Format > Language:

Modify style dialog

Tick the 'Do not check spelling or grammar' checkbox:

Language dialog

Highlight your code and use the new style. Any text not in this style will still be spellchecked:

Result