Toggle spellling and grammar
-
- 5StarLounger
- Posts: 889
- Joined: 25 Jan 2010, 16:26
- Location: Garden Grove, CA 92844 USA
Toggle spellling and grammar
Is there any way to toggle on/off the spelling and grammar checks? Sometimes I copy/paste code into Word so I can use it as a reference when writing CSS rules and the little squiggly lines of red and green make it tough to read. I would love to have a button I could click to just turn it off for a while.
Thanks
Thanks
Don
-
- Administrator
- Posts: 78790
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Toggle spellling and grammar
Select File > Options, then click Proofing. Clear or tick the check boxes "Check spelling as you type" and "Check grammar errors as you type", then click OK.
To automate this, create the following macro in a standard module in your default template Normal.dotm:
You can assign this macro to a Quick Access Toolbar button, a custom ribbon button and/or a keyboard shortcut.
To automate this, create the following macro in a standard module in your default template Normal.dotm:
Code: Select all
Sub ToggleChecking()
If Options.CheckGrammarAsYouType Then
Options.CheckGrammarAsYouType = False
Options.CheckSpellingAsYouType = False
Else
Options.CheckGrammarAsYouType = True
Options.CheckSpellingAsYouType = True
End If
Application.ScreenRefresh
End Sub
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 889
- Joined: 25 Jan 2010, 16:26
- Location: Garden Grove, CA 92844 USA
Re: Toggle spellling and grammar
Thank you very much. Where would I enter this code so that it would be available on all documents. When I do Alt-F11, it only shows 'this document'
I am using Word 2007.
I am using Word 2007.
Don
-
- 5StarLounger
- Posts: 889
- Joined: 25 Jan 2010, 16:26
- Location: Garden Grove, CA 92844 USA
Re: Toggle spellling and grammar
Wait - I think in the Normal template where I have other macros. Correct?
Don
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: Toggle spellling and grammar
Yep...the module in Normal.
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- 5StarLounger
- Posts: 889
- Joined: 25 Jan 2010, 16:26
- Location: Garden Grove, CA 92844 USA
Re: Toggle spellling and grammar
That works great! I wonder if there is a way to change the appearance of the button or otherwise show some indication that the macro is active. I fear turning it on and forgetting that it is on. My spelling is bad enough that it really helps when I am normally writing a document.
Don
-
- Administrator
- Posts: 78790
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Toggle spellling and grammar
Yep. I mentioned Normal.dotm in my reply.
There is no easy way to make a QAT or ribbon button change appearance - it requires XML programming; I'm afraid I cannot help you with that.
There is no easy way to make a QAT or ribbon button change appearance - it requires XML programming; I'm afraid I cannot help you with that.
Best wishes,
Hans
Hans
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: Toggle spellling and grammar
How about writing code in the ThisDocument.Close event to turn spelling back on when you close the doc.
Code: Select all
Sub ActivateSpelling()
Options.CheckGrammarAsYouType = True
Options.CheckSpellingAsYouType = True
End Sub
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- 5StarLounger
- Posts: 889
- Joined: 25 Jan 2010, 16:26
- Location: Garden Grove, CA 92844 USA
Re: Toggle spellling and grammar
I was thinking that maybe when I invoke this macro I could change the page color to yellow. then when I turn it off, change it back to white.
It works! I modified the macro by recording then manually merging... ended up with:
I expect the recorded part may be a little clumsy but I don't know how to clean it up. Probably not important, anyway.
It works! I modified the macro by recording then manually merging... ended up with:
Code: Select all
Sub ToggleChecking()
If Options.CheckGrammarAsYouType Then
Options.CheckGrammarAsYouType = False
Options.CheckSpellingAsYouType = False
ActiveDocument.Background.Fill.ForeColor.RGB = RGB(255, 255, 0)
ActiveDocument.Background.Fill.Visible = msoTrue
ActiveDocument.Background.Fill.Solid
Else
Options.CheckGrammarAsYouType = True
Options.CheckSpellingAsYouType = True
ActiveDocument.Background.Fill.Visible = msoFalse
End If
Application.ScreenRefresh
End Sub
Don
-
- 5StarLounger
- Posts: 889
- Joined: 25 Jan 2010, 16:26
- Location: Garden Grove, CA 92844 USA
Re: Toggle spellling and grammar
Not so good after all as it only affects the document I am in when I turn on the macro. If I switch to another document, the macro stays active but the page color is normal (no color).
Don
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: Toggle spellling and grammar
Have you tried the suggestion I posted.
When you switch to different docs, you can toggle spelling on/off, but when you close any doc, the spelling will auto be turned on again.
When you switch to different docs, you can toggle spelling on/off, but when you close any doc, the spelling will auto be turned on again.
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- 5StarLounger
- Posts: 889
- Joined: 25 Jan 2010, 16:26
- Location: Garden Grove, CA 92844 USA
Re: Toggle spellling and grammar
Didn't see that Rudi,
1) How do I get to the ThisDocument.Close event so I can enter the code?
2) Not sure I understand what you mean by 'When you switch to different docs, you can toggle spelling on/off'. Currently it retains the on/off state as I switch documents... is that the same as what you are saying?
3) Do I understand correctly that if I close any document, it toggles spell check on for all documents?
1) How do I get to the ThisDocument.Close event so I can enter the code?
2) Not sure I understand what you mean by 'When you switch to different docs, you can toggle spelling on/off'. Currently it retains the on/off state as I switch documents... is that the same as what you are saying?
3) Do I understand correctly that if I close any document, it toggles spell check on for all documents?
Don
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: Toggle spellling and grammar
Hi,
See image for where to put macro...
I was referring to your toggle button on the QAT. When you switch to another doc, you can toggle the macro on/off based on if you need spelling or not.
Not sure... Word VBA has nipped me in the butt a few times as I parallel it to Excel VBA and they are two different animals. Test and see if it works that way?
See image for where to put macro...
I was referring to your toggle button on the QAT. When you switch to another doc, you can toggle the macro on/off based on if you need spelling or not.
Not sure... Word VBA has nipped me in the butt a few times as I parallel it to Excel VBA and they are two different animals. Test and see if it works that way?
You do not have the required permissions to view the files attached to this post.
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- 5StarLounger
- Posts: 889
- Joined: 25 Jan 2010, 16:26
- Location: Garden Grove, CA 92844 USA
Re: Toggle spellling and grammar
Thanks Rudi, as far as I can tell it has no effect. For example, doc1 and doc2 two are open. Toggle off the spell check. It is off on both docs.
close doc2; doc1remains open with spell check toggled off.
My guess is that that macro toggles spell check on just prior to closing.
I can live with what I have - just have to remember that it is on... I was hoping it would change the background color on all documents so that if I did switch docs, I would have that constant reminder the spell check is toggled off.
close doc2; doc1remains open with spell check toggled off.
My guess is that that macro toggles spell check on just prior to closing.
I can live with what I have - just have to remember that it is on... I was hoping it would change the background color on all documents so that if I did switch docs, I would have that constant reminder the spell check is toggled off.
Don
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: Toggle spellling and grammar
You could try looping through the open documents...
Untested...but try this code
Untested...but try this code
Code: Select all
Sub ToggleChecking()
Dim Doc As Document
If Options.CheckGrammarAsYouType Then
Options.CheckGrammarAsYouType = False
Options.CheckSpellingAsYouType = False
For Each Doc In Application.Documents
Doc.Background.Fill.ForeColor.RGB = RGB(255, 255, 0)
Doc.Background.Fill.Visible = msoTrue
Doc.Background.Fill.Solid
Next Doc
Else
Options.CheckGrammarAsYouType = True
Options.CheckSpellingAsYouType = True
For Each Doc In Application.Documents
Doc.Background.Fill.Visible = msoFalse
Next Doc
End If
Application.ScreenRefresh
End Sub
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- Microsoft MVP
- Posts: 1320
- Joined: 24 May 2013, 15:33
- Location: Warminster, PA
Re: Toggle spellling and grammar
A better way -- without any macros at all -- is to define a character style that contains the "Do not check spelling or grammar" setting, and apply that style to all of your code.
To create the style:
To create the style:
- Select some of the code text. If you want a specific font or other formatting for code, such as Courier New 9 pt, apply that formatting to the selected text.
- Click Review > Language > Set Proofing Language.
- In the dialog, check the box for "Do not check spelling or grammar" and click OK.
- On the Home tab, click the lower of the two down-arrows at the right end of the Styles gallery, and click "Save Selection as a New Quick Style" in the dropdown.
- Change the suggested name to something such as Code. IMPORTANT: Do not click OK yet!
- Click the Modify button.
- In the dialog, click the Style Type dropdown and choose Character. Click the "New documents based on this template" option, and then click OK.
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: Toggle spellling and grammar
As usual Jay...top notch suggestion/advice (at least IMHO)
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- 5StarLounger
- Posts: 889
- Joined: 25 Jan 2010, 16:26
- Location: Garden Grove, CA 92844 USA
Re: Toggle spellling and grammar
Thanks Jay, that is a great solution. Question, though...
What, exactly, does the "New documents based on this template" option mean? I currently use normal.dotx and would not want to change to a 'Code' template. Forgive me if I totally miss the point but I think I did.
What, exactly, does the "New documents based on this template" option mean? I currently use normal.dotx and would not want to change to a 'Code' template. Forgive me if I totally miss the point but I think I did.
Don
-
- Microsoft MVP
- Posts: 1320
- Joined: 24 May 2013, 15:33
- Location: Warminster, PA
Re: Toggle spellling and grammar
You're creating a new style, not a new template. That style has to be stored somewhere. There are two choices: only in the current document, or both in the current document and in the template that the current document is based on.dasadler wrote:What, exactly, does the "New documents based on this template" option mean? I currently use normal.dotx and would not want to change to a 'Code' template. Forgive me if I totally miss the point but I think I did.
Assuming that the document is based on normal.dotm, selecting the "New documents based on this template" option means that the style will be saved both in the current document and in the normal.dotm template. Then the Code style will be available in all new documents that you later base on normal.dotm.
If you left the "Only in this document" option selected, then the Code style would be stored just in the current document, and it wouldn't be available in any other document (unless you recreated it from scratch in that other document).
One other thing I should have added to the previous post: If you have the option turned on to "prompt before saving Normal template" (in File > Options > Advanced), then the next time you close Word after creating the new style, you'll get a message asking whether to save changes in Normal.dotm. (Unfortunately, it has no way to tell you what the changes are -- you have to remember that you asked for the style to be saved there.) If you say yes, the new style will be saved in the template; if you say no, it will be discarded and won't be there the next time you want it.
-
- 5StarLounger
- Posts: 889
- Joined: 25 Jan 2010, 16:26
- Location: Garden Grove, CA 92844 USA