VBA to Cancel a Dialogue

FracinDean

Board Regular
Joined
Jul 11, 2011
Messages
110
Office Version
  1. 365
Platform
  1. Windows
I'm trying to generate word lists that meet certain tests. I would like to use Spellcheck to decide when something is actually a word. I am able to determine if something is a word from the return value "TRUE" or "FALSE", but I have not been able to determine how to close the spell check dialogue box from within my code. I always want to select the "Cancel" option for the dialogue box. I don't the issue is just about spell check, but about how to programmatically respond to a dialogue box when the fact that the dialogue opened has paused the execution of your code. Here is my code:

Code:
Dim isWord as Boolean, wordToCheck as string
Range("myWord").Select
wordToCheck = Selection.Value
isWord = Selection.CheckSpelling(wordToCheck)
Msgbox ("Result is " & isWord)
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I was able to locate some information in another source. What I found was that if the .CheckSpelling method is called from a function, then the Boolean value will be returned without opening the dialogue box. I think it is likely that it will work for other methods that would open a dialogue, but I have not tested those. Here is what worked:

Code:
Function SpellingIsCorrect(ByVal strInput) As Boolean
  SpellingIsCorrect = Application.CheckSpelling(strInput)
End Function

along with the following in my Sub

Code:
Dim isAWord as Boolean, theWord as String
theWord = Selection.Value
isAWord = SpellingIsCorrect(theWord)

This is using my default dictionary and returning TRUE or FALSE without opening a dialogue.
 
Upvote 0
Solution

Forum statistics

Threads
1,216,082
Messages
6,128,700
Members
449,464
Latest member
againofsoul

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top