I'd like to come up with a word game or two, and would need some help. Is there a way to scan a string through a dictionary to check if it's a real word, or is there a way to take that string and access a website like an online scrabble dictionary?
I'd like to come up with a word game or two, and would need some help. Is there a way to scan a string through a dictionary to check if it's a real word, or is there a way to take that string and access a website like an online scrabble dictionary?
This macro will check spelling on all sheets in a workbook by enabling the Windows Spell Checker.
It shouldn't be necessary to use an online dictionary. The challenge now is to determine how you
can utilize the function of the Spell Checker in your project.
Sub SpellChecker() Dim s As Worksheet For Each s In Worksheets s.Cells.CheckSpelling Next s End Sub
Thank you for your response, but I'm working in PowerPoint, and not Excel. I don't think that's even possible in PowerPoint?
It is possible to activate the Excel Spell Check from PowerPoint but I don't see how it could help. The CheckSpelling method has no return so there is no obvious way of knowing whether the word is correct.
John Wilson
Microsoft PowerPoint MVP
Amazing Free PowerPoint Tutorials
http://www.pptalchemy.co.uk/powerpoi...tutorials.html
This code would search a text file called dic.txt on your desktop
You can download a copy of dic.txt from hereSub chex_Word() ' word goes here If Not Word_exists("ABout") Then MsgBox "It's not a word I know.", vbInformation Else MsgBox "It'a a word I know.", vbInformation End If End Sub Function Word_exists(strSearch As String) As Boolean Dim strPath As String strPath = Environ("USERPROFILE") & "\Desktop\dic.txt" Dim strLine As String Dim FileNum As Integer strSearch = LCase(strSearch) FileNum = FreeFile Open strPath For Input As #FileNum Do While Not EOF(FileNum) Line Input #FileNum, strLine If InStr(1, strLine, strSearch, vbTextCompare) > 0 Then Word_exists = True Exit Do End If Loop Close #FileNum End Function
A) It does not contain ALL words
B) I cannot remember where I got it so cannot attribute.
John Wilson
Microsoft PowerPoint MVP
Amazing Free PowerPoint Tutorials
http://www.pptalchemy.co.uk/powerpoi...tutorials.html
I'll give that a shot. Thanks John!
It'd probably be faster to read the list of words one time at the beginning and then just check them as you go
Option Explicit Dim D As Object Sub LoadDic() Dim strPath As String, strLine As String Dim FileNum As Integer Set D = CreateObject("Scripting.Dictionary") strPath = Environ("USERPROFILE") & "\My Documents\dic.txt" FileNum = FreeFile Open strPath For Input As #FileNum Do While Not EOF(FileNum) Line Input #FileNum, strLine Call D.Add(strLine, strLine) Loop Close #FileNum End Sub Function IsWord(s As String) As Boolean IsWord = D.exists(s) End Function Sub drv() MsgBox IsWord("cat") MsgBox IsWord("dog") MsgBox IsWord("zootoxin") MsgBox IsWord("qqqqqqqq") End Sub
---------------------------------------------------------------------------------------------------------------------
Paul
Remember: Tell us WHAT you want to do, not HOW you think you want to do it
1. Use [CODE] ....[/CODE ] Tags for readability
[CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
2. Upload an example
Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
3. Mark the thread as [Solved] when you have an answer
Thread Tools (on the top right corner, above the first message)
4. Read the Forum FAQ, especially the part about cross-posting in other forums
http://www.vbaexpress.com/forum/faq...._new_faq_item3
I was thinking that way too but I was surprised how fast the original code I posted runs.
John
John Wilson
Microsoft PowerPoint MVP
Amazing Free PowerPoint Tutorials
http://www.pptalchemy.co.uk/powerpoi...tutorials.html
Yea it's probably a wash for a few words. But ...
1. Run time is linear function of number of words being checked, 100 words = 100 times as long
2. It's on disc each time which is slower than memory, plus opening and closing takes time
3. Since the file is sorted, once you go past the word you're searching for you can exit the loop
4. Since the file is sorted, you could use a binary search and just narrow in on the word (possibly faster)
Maybe something like this untested tweak
Sub chex_Word() ' word goes here If Not Word_exists("ABout") Then MsgBox "It's not a word I know.", vbInformation Else MsgBox "It's a word I know.", vbInformation End If End Sub Function Word_exists(strSearch As String) As Boolean Dim strPath As String strPath = Environ("USERPROFILE") & "\Desktop\dic.txt" Dim strLine As String Dim FileNum As Integer Word_exists = False strSearch = LCase(strSearch) FileNum = FreeFile Open strPath For Input As #FileNum Do While Not EOF(FileNum) and strLine < strSearch Line Input #FileNum, strLine If strLine = strSearch Then Word_exists = True Loop Close #FileNum End Function
---------------------------------------------------------------------------------------------------------------------
Paul
Remember: Tell us WHAT you want to do, not HOW you think you want to do it
1. Use [CODE] ....[/CODE ] Tags for readability
[CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
2. Upload an example
Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
3. Mark the thread as [Solved] when you have an answer
Thread Tools (on the top right corner, above the first message)
4. Read the Forum FAQ, especially the part about cross-posting in other forums
http://www.vbaexpress.com/forum/faq...._new_faq_item3
I follow the reasoning but my test txt file was 128,000 word and even checking a word way down the list (waste) it returned an answer in 0.2 sec. I actually thought is would take longer.
Here it is running http://screencast.com/t/S4TxUnXaqg
John Wilson
Microsoft PowerPoint MVP
Amazing Free PowerPoint Tutorials
http://www.pptalchemy.co.uk/powerpoi...tutorials.html
Yes it is fast and yes I though it'd take longer also
All I was saying is that checking 100 works would take 20 seconds, and that when you find a match, your macro still reads to the end of the file
---------------------------------------------------------------------------------------------------------------------
Paul
Remember: Tell us WHAT you want to do, not HOW you think you want to do it
1. Use [CODE] ....[/CODE ] Tags for readability
[CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
2. Upload an example
Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
3. Mark the thread as [Solved] when you have an answer
Thread Tools (on the top right corner, above the first message)
4. Read the Forum FAQ, especially the part about cross-posting in other forums
http://www.vbaexpress.com/forum/faq...._new_faq_item3
The Exit Do would jump out of the loop once a match was found
John Wilson
Microsoft PowerPoint MVP
Amazing Free PowerPoint Tutorials
http://www.pptalchemy.co.uk/powerpoi...tutorials.html
Sorry - I missed that part
My bad
---------------------------------------------------------------------------------------------------------------------
Paul
Remember: Tell us WHAT you want to do, not HOW you think you want to do it
1. Use [CODE] ....[/CODE ] Tags for readability
[CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
2. Upload an example
Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
3. Mark the thread as [Solved] when you have an answer
Thread Tools (on the top right corner, above the first message)
4. Read the Forum FAQ, especially the part about cross-posting in other forums
http://www.vbaexpress.com/forum/faq...._new_faq_item3
Working great, thanks John and Paul!
Thanks a lot for this brilliant solution! It might helps me a lot!
missed thread, sorry mistake