Macro doesn't always work.

Here's a good challenging question.  I added a quick access toolbar (QAT) icon that invokes a macro I wrote to toggle the "Check spelling as you type" function that is otherwise  accessed through the File tab, Options, Proofing, and checking or un-checking under the heading "When correcting spelling and grammar in Word" the box for Check spelling as you type.  But this QAT icon sometimes does not work.  I also have QAT icons for "Show all formatting marks" and "Final: Show Markup" that always work.  If instead of clicking on the QAT icon I run the macro directly by going to the View tab and clicking on Macros, then clicking on this particular macro and then clicking on Run, it still sometimes doesn't toggle the Check-spelling-as-you-type option.  So, it seems like it's the macro that sometimes doesn't work.  Any suggestions on how to make the macro always work?  Below is the macro script that toggles the spellchecker.  Thanks.

 

________________________________________________________________________________________

 

Sub ShowAll()

With ActiveWindow

    .View.ShowAll = Not .View.ShowAll

End With

Application.ScreenRefresh

End Sub

Sub SpellCheckAsYouType()

With Options

    .CheckSpellingAsYouType = Not .CheckSpellingAsYouType

End With

Application.ScreenRefresh

End Sub

Sub ViewMarkups()

    With ActiveWindow.View

        .ShowRevisionsAndComments = Not .ShowRevisionsAndComments

End With

Application.ScreenRefresh

End Sub

________________________________________________________________________________________

 

 
Under what circumstances doesn't it work?
Graham Mayor (Microsoft Word MVP 2002-2019)
For more Word tips and downloads visit my web site
https://www.gmayor.com/Word_pages.htm

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

I forgot to mention that It happens about 10 to 20 percent of the time when I execute the macro.  I haven't noticed any other particular circumstance when it doesn't work.  I always have a Windows Explorer and Outlook open.  I might also have EXCEL, Internet Explorer, and Acrobat open.  The Word file might be one or several more files open, but it can happen with just one Word file, with just text with no pictures or tables.  It happens in print layout or draft views.  And when it happens, to try to correct it as a method of desperation, for lack of better words, I click on other QAT buttons I created that toggle "show all formatting marks" and "show markups" options, and it still doesn't make the spell-checker macro work.  It get cured when I go through the File tab, then options, etc., and change the setting the long way.  After that the macro works most of the time.  So, this macro seems to malfunction randomly.  If you think it would help when I get to my work computer next time I'll note all of the circumstances that I haven't yet noted.  And do you think it would help if at the end of each workday I actually log off, or even restart my computer?  Now I just put on lock screen at day's end cuz it saves time logging on the next day, and reboot only on Fridays or after IT downloads updates.  Thanks, and I hope we find out the cause before my company switched to the next version of Windows, LOL.

2 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

The macro should certainly work. It is difficult to say why it does not all the time, which is why I asked the question, in an attempt to narrow down the circumstances. It won't appear to do anything, for example, if the text in the document is formatted with the no proofing switch.

Word 2010 appears to store up error conditions. It may be something to do with the document recovery, but I have found no way to clear the fault condition short of rebooting, so doing that when problems occur should be worthwhile.

Checkout http://www.gmayor.com/what_to_do_when_word_crashes.htm  then http://word.mvps.org/FAQs/AppErrors/ProblemsStartingWord.htm  also as these links cover all the common troubleshooting tips.
Graham Mayor (Microsoft Word MVP 2002-2019)
For more Word tips and downloads visit my web site
https://www.gmayor.com/Word_pages.htm

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

A new problem possibly related to the above one is that sometimes when I execute one of the above macros, either through the QAT or through View tab then the Macros button, is that I get the following message, which says, "Code execution has been interrupted":

 

 

 

 

If I click "Debug", it opens the VBA editor, and the line in the Macro that says, "End Sub" is highlighted in yellow with an arrow pointing to it.  Could this problem be related to the first problem reported above regarding the spell checker not always working?  Whenever this new problem occurs, it happens for any of the three macros I created.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Open the VBA editor. At the top of the module(s) containing your code and before the macro(s), enter Option Explicit

From the toolbar, select Tools > Options  > Editor > Check all the boxes in the top section, but particularly 'Require Variable Declaration' (which will add Option Explicit to your new modules).

Then click Debug > Compile Normal. What is then highlighted in error? It could be that you have duplicated End Sub.
Graham Mayor (Microsoft Word MVP 2002-2019)
For more Word tips and downloads visit my web site
https://www.gmayor.com/Word_pages.htm

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

The second problem I posted above that says, "Code execution has been interrupted" stopped.  So now I'm back to the first good challenging problem stated above that started this whole discussion, namely the QAT button sometimes not working to toggle the Spell-check-as-you-type option.  Sometimes it still doesn't work.  But one weird thing I noticed is that when I click on the QAT button it always DOES change what is displayed in the check-box for "Check spelling as you type" shown when going through the File tab, Options, Proofing sequence.  And even if I have the "Check spelling as you type" box checked, and I click on the OK button to exit this window, the spelling errors still are not highlighted.  And to make it even more weird, this could be happening in one document, while in another document the QAT button works just fine.  And this morning even when I opened a new document and used both the QAT button and the long File/Options/checkbox method, spelling errors still weren't displayed.  But everything worked after I restarted Word.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated November 14, 2023 Views 5,714 Applies to: