PDA

View Full Version : Solved: prompt user to spell check when document is closed



RCinSTP
10-10-2012, 01:25 PM
I have some very simple VBA code below. One macro runs automatically when the document opens and the other runs automatically when the document is closed. The first sets the spell check property to False to indicate that spell check has not been run. When the document closes the message box should show that spell check has not been run "False" but instead it always switches it to True to indicate that spell check has been run. I want to prompt users when they close the document and ask if they ran spell check but I don't want to ask them if they already ran spell check.

Sub AutoOpen()
Application.ResetIgnoreAll
ActiveDocument.SpellingChecked = False
ActiveDocument.GrammarChecked = False
End Sub

Sub AutoClose()
Dim boSpellingChecked As Boolean
boSpellingChecked = ActiveDocument.SpellingChecked
MsgBox boSpellingChecked
End Sub

gmaxey
10-10-2012, 03:04 PM
You would need to turnoff the option Check Spelling as you type for that code to work. I suggest this instead:

Sub AutoClose()
If ActiveDocument.SpellingErrors.Count > 0 Then
If MsgBox("Your document contains one or more spelling errors." _
& " Do you want to run the spelling checker?", vbQuestion + vbYesNo, _
"Spelling Errors Detected") = vbYes Then
ActiveDocument.CheckSpelling
End If
End If
End Sub

RCinSTP
10-11-2012, 06:15 AM
gmaxey ROCKS!!!! Thank you sooo much. Your solution works perfectly. Thanks for teaching me something new.