# Visual Basic > Visual Basic 6 and Earlier >  [RESOLVED] Dictionary Access

## AccessShell

I have written a small VB 6 program using the Microsoft Word 11.0 object library.  The program works fine when  I declare "dim mwd as New Word.Application" and declare "Dim mwdsp as Word.SpellingSuggestions".

But the dictionary that comes with Office 11.0 is rather old.  I don't think I can attach a newer dictionary to MS Word 2003.  Without moving on .NET, how can I access a newer dictionary, or a more comprehensive American English dictionary in VB6 without changing my code?

Thanks

----------


## SamOscarBrown

I have not idea WHAT dictionary my Office 2013 uses..., but with this code in a module, I spell check my apps with it:

(accessed like:     

```
Clipboard.Clear
    Clipboard.SetText Text3.Text
    Text3.Text = SpellChk()
```

)



```
Option Explicit

Declare Function CoAllowSetForegroundWindow Lib "ole32.dll" (ByVal pUnk As Object, ByVal lpvReserved As Long) As Long

Public Function SpellChk() As String
    Dim WordApp As Object
    Dim objDoc As Object 'Word.Document
    Dim lOrigTop As Long
    Dim lErr As Long
    On Error GoTo SpellChkErr
    ' Create a Word document object
    Set WordApp = CreateObject("Word.Application")
    CoAllowSetForegroundWindow WordApp, 0
    Set objDoc = WordApp.Documents.Add
    ' Position Word off screen to avoid having document visible
    lOrigTop = WordApp.Top
    WordApp.WindowState = 0
    WordApp.Top = -3000
    WordApp.Visible = True
    WordApp.Activate
    ' Assign the text to the document and check spelling
    With objDoc
        .Content.Paste
        .Activate
        .CheckSpelling
        ' After the user has made changes, use the clipboard to
        ' transfer the contents back to the text box
        .Content.Copy
        SpellChk = Clipboard.GetText(vbCFText)
        ' Close the document and exit Word
        .Saved = True
        .Close
    End With
    Set objDoc = Nothing
    WordApp.Visible = False
    WordApp.Top = lOrigTop
    WordApp.Quit
    Set WordApp = Nothing
    Exit Function
SpellChkErr:
    lErr = Err
    SpellChk = Clipboard.GetText(vbCFText)
    Screen.MousePointer = vbNormal
    Select Case lErr
        Case 91, 429
            MsgBox "MS Word cannot be found!", vbExclamation
        Case Else
            MsgBox "Error: " & Err & " - " & Error$(Err), vbExclamation, App.ProductName
    End Select
End Function
```

----------


## LaVolpe

And for the OP, the difference is that you are loading a specific version of Word (early binding) whereas Sam is loading whatever version the user may have (late binding). In either case, Word is assumed to be present. There are differences with how you have to create the objects using Early vs. Late binding

----------


## AccessShell

Why would my OS have a different Dictionary.  I thought MS Office Pro supplies the dictionary?  

Thanks

----------


## LaVolpe

Don't know if dictionary is different or not. Different versions of MS, possibly different versions of the dictionary (more current for newer Office versions). Does MS have a single dictionary it shares among all versions of office? Don't know.

----------


## AccessShell

Used supplied  code from SamOscarBrown and got  the same answer as with my code.  The same dictionary was referenced by bot code.

----------


## si_the_geek

That is to be expected, as SamOscarBrown's code uses whatever version of Word is installed, so will be using the same version as your code does.

----------


## LaVolpe

Well to try to answer this question, if I'm understanding you correctly



> But the dictionary that comes with Office 11.0 is rather old.  I don't think I can attach a newer dictionary to MS Word 2003.  Without moving on .NET, how can I access a newer dictionary, or a more comprehensive American English dictionary in VB6 without changing my code?


You can only access whatever MS Office dictionary is on the user's system with the code you have. And I would think that if the user had a version less than Office 11, you would get an error; whereas Sam's code doesn't care which Office version exists as long as the Word application has the methods/properties he used in his sample code. The same office dictionary, I'd imagine, is used with all installed office products on that machine.

To use another dictionary (online or on the system), you'll need to change your code to include calling whatever methods/properties that that specific dictionary exposes.

----------


## AccessShell

I fully agree with you LaVolpe.  I think, then, If I am able to get another dictionary on my computer, or via an online inquiry, I might be able  to access that dictionary with some modified code.  I don't think there are any VB6 references, components or objects that easily does this.

----------


## LaVolpe

Well couple problems with on-line dictionaries:
1) user's network availability & will the target site be available
2) will the online site allow you to manipulate it remotely for this purpose? 
3) can it spell-check more than 1 word at a time? 
4) will it give you suggested corrections?

Problems with other dictionaries (not Office)
1) you'll need to transfer those with your program's setup files
2) who updates these?
3) when updated, now you need to redistribute the dictionary
Example: There is a project on planetsourcecode. How often is that updated, if at all? See 2nd post in this thread

And of course, what if no dictionary is available at all? If you're not distributing one, then you simply can't do spell checks, can you?

----------


## AccessShell

I looked at the code you suggested.  Downloaded it and ran it.  Sometimes it worked; sometimes it didn't.  Besides, the code is way to advanced for me.  I lost it in VB6 when classes were developed.  I now only write without classes.

Thanks for your help.  I think I will consider this thread closed.

----------


## AccessShell

I did some some digging into this.  When I ran the program on WIN 10, I got this error

"Err.Source = C:\WINDOWS\Help\VBENLR98.CHM"
"Err.Description   = Automation error Library not registered."
"Err.HelpContext = 1000440"

I don't know what a "CHM" file is.  This file is not present anywhere on my WIN 10 computer.  However, I looked at my WIN 7, VMXP, computer and did NOT find this file either.  Yet, the program works on VMXP.

I believe the program was originally written in January of 2003.  I don't know what version of VB existed then.
Could that have anything to do with the problem?
I looked on the VMXP computer and could not find the CHM file.  I was going to copy it onto the WIN 10 computer.

----------


## AccessShell

This is the code


```
Private Sub cmdCheck_Click()Dim wd        As New Word.Application
Dim wdsp      As Word.SpellingSuggestions
Dim i         As Integer
Dim strBuffer As String
Dim varBuffer As Variant
Dim synList   As Variant
Dim antList   As Variant
Dim synFound  As Boolean


    On Error GoTo cmdCheckErr
    
    lblSugs.Caption = NUM_OF_SUGS & CStr(0)
    lblSyns.Caption = NUM_OF_SYNS & CStr(0)
    lblAnts.Caption = NUM_OF_ANTS & CStr(0)
    lblMsg.Caption = ""
    lstSuggestions.Clear
    lstSynonyms.Clear
    lstAntonyms.Clear
    
    strBuffer = txtMain.Text
    
    cmdCheck.Enabled = False
    cmdQuit.Enabled = False
    
    frmMain.MousePointer = vbHourglass
    wd.Documents.Add        '***DIES HERE***********************************
   
    If Not wd.CheckSpelling(strBuffer) Then
        txtMain.ForeColor = vbRed
        lblMsg.Caption = "Spelling Incorrect!"
        lblMsg.ForeColor = vbRed
        Set wdsp = wd.GetSpellingSuggestions(strBuffer)
        lblSugs.Caption = NUM_OF_SUGS & CStr(wdsp.Count)
        
        For i = 1 To wdsp.Count
            lstSuggestions.AddItem wdsp(i).Name
        Next i
    Else
        varBuffer = CVar(strBuffer)
        lblMsg.Caption = "Spelling OK"
        lblMsg.ForeColor = vbBlue
        varBuffer = CVar(strBuffer)
        
        'Get the Synonyms
        synFound = SynonymInfo(Word:=varBuffer, LanguageID:=wdEnglishUS).Found
        If synFound = True Then
            synList = SynonymInfo(Word:=varBuffer, LanguageID:=wdEnglishUS).SynonymList(Meaning:=1)
            For i = 1 To UBound(synList)
                lstSynonyms.AddItem synList(i)
            Next i
            lblSyns.Caption = NUM_OF_SYNS & CStr(UBound(synList))
        End If
        
        'Get the Antonyms
        'antList = SynonymInfo(Word:=varBuffer, LanguageID:=wdEnglishUS).AntonymList
        antList = SynonymInfo(varBuffer, wdEnglishUS).AntonymList
        For i = 1 To UBound(antList)
            lstAntonyms.AddItem antList(i)
        Next i
        lblAnts.Caption = NUM_OF_ANTS & CStr(UBound(antList))
    End If
    
    wd.Documents.Close
    wd.Quit
    Set wd = Nothing
    txtMain.ForeColor = vbBlack
    frmMain.MousePointer = vbDefault
    cmdCheck.Enabled = True
    cmdQuit.Enabled = True
    Exit Sub
    
cmdCheckErr:
    MsgBox Err.Description & ", " & Err.Number
    Debug.Print "Err.Description = " & Err.Description & _
                "Err.HelpContext = " & Err.HelpContext & _
                "Err.HelpFile    = " & Err.HelpFile
    wd.Quit
    
End Sub
```

----------


## yereverluvinuncleber

VBENLR98.chm is a compiled HTML file, a help file for the Microsoft scripting runtime.

----------


## baka

I added spellchecking in my "build-in" game-editor so the writer has a bit of help when writing the dialogs/text.
a few things I needed to do was to create a "error-handler", this because sometimes word would close, if so, the program would re-initialize.
so, 1 year passed and another person wanted to help with a side-story, but he got a crash. and investigating it showed word was the culprit.
he told me has word, but not the spell-checking.
after that I removed it all and created my own spell-checking function. and Im quite happy with that. now theres no problem whoever use it,
since its not dependent of word and what OS and version or addon the person has.

----------


## AccessShell

That doesn't explain why, in my case, the version of Word is the same (2003).

Nor why the CHM file does not appear in either OS.  Yes, I still have my WIN 7 with the VMXP.  The only difference, I am aware of, is the WIN 7 (witt the VMXP) is NOT connected to the internet.

----------


## baka

the problem is NOT the CHM but:
Automation error Library not registered

it means word is not working properly.

----------


## techgnome

> That doesn't explain why, in my case, the version of Word is the same (2003).


Why would it be different? If you've got Word 2003 installed, that's what going to be used. If you were to upgrade it to a newer version and use Sam's code... then you should see it using a different version. 


-tg

----------


## AccessShell

Does this mean that all I need do is reinstall MS Office 2003 Pro?  I don't have MS Office 365 installed.  Is that a deal breaker?  Is MS trying to tell me use 365?

----------


## baka

each word is different and can have a different structure.
also, it can be its not initialized correctly, or its not registered correctly to the register so VB can fetch it.
or the register has a wrong ID, so there no match.

but the problem is word.
wd.Documents.Add

Documents.Add < is not a valid command.
could be u need to do
wd.-something-.Documents.Add or something else.

thats the problem here. u need to know the right command.

when I used word, we had different versions. but it worked because all word versions did have the same command.
I have not used Documents.Add

----------


## AccessShell

I found this 
https://answers.microsoft.com/en-us/...b-e5866fa97356

----------


## baka

could be that as well.
but I know that not all commands are the same.
try to remove Documents.Add and see what happens.
I only used word by word. so I never did grammar.
worked for me. but word need to have spell-dictionary installed.

or create your own spell-check, is not that hard to do.

----------


## AccessShell

I don't know why I didn't try this before,  I ran the original code on the Win7 computer.  It runs correctly.  It lists the word and it's synonyms and antonyms correctly if it is a word. Otherwise, It gives suggestions for correct words.

----------


## AccessShell

Even though the program crashes, I successfully compiled it.  Of course, it crashed on my computer. (Win Ver 22H2, but last week it was 21H2 and it still crashed).

I copied the exe onto my friends Win10 laptop (21H2) with Office 2003 Pro.  That computer does not have VB6 installed.  The program worked correctly. 

I am now even more confused.

----------


## baka

I told u, its Documents.Add that is not working.
the word version in your computer don't have that command so it crash.

----------


## AccessShell

I just said that my friend's computer has the same version of Word - Office Pro 2003

----------


## baka

something is different.
did u try to remove Documents.Add and only use the CheckSpelling function and see if it works.
if not, it means theres something wrong with the registry.

----------


## AccessShell

Yes.  No change.  Do you think I should re-install Office?

----------


## AccessShell

Oh, I wonder.  I also have LibreOffice installed on my computer.  Maybe there is an interaction?????

----------


## baka

create a new project and add this



```
Dim wd As Object
Dim enable As Boolean

Function CheckWord(ByVal Word$) As Boolean
    If enable Then
        On Error GoTo isError
        CheckWord = wd.CheckSpelling(Word$)
    End If
    Exit Function
isError:
    InitializeWord
End Function

Sub InitializeWord()
    On Error Resume Next
    Set wd = Nothing
    Set wd = CreateObject("Word.Application")
    If Err.Number = 0 Then
        enable = True
        wd.Options.IgnoreMixedDigits = False
        wd.Options.IgnoreUppercase = False
    End If
End Sub

Sub DestroyWord()
    If enable Then
        On Error Resume Next
        wd.quit
        Set wd = Nothing
        enable = False
    End If
End Sub

Private Sub Form_Load()
    InitializeWord
    Debug.Print CheckWord("testing")
    Debug.Print CheckWord("wordnotfound")
    DestroyWord
End Sub
```

and see if it works or not.
this is what I used in my program before I changed to my own spellcheck function.

----------


## AccessShell

Baka, your code works.  I will rewrite my program.

I have searched the internet for "Automation error Library not registered".  I discovered that the code


```
wd.Documents.Add
```

is not really the problem.  All article I found suggest that I may have remnants of another version of "Office" on my computer.  The only real solution is to go into the registry and delete the others.  I don't remember any other office on this computer.  I do remember being nagged my MS for Office 365.  I finally removed the nag.  I don't remember how.
I am not eager to go into the registry.

----------


## baka

in my code add:



```
Private Sub Form_Load()
    InitializeWord
    wd.Documents.Add
    Debug.Print CheckWord("testing")
    Debug.Print CheckWord("wordnotfound")
    DestroyWord
End Sub
```

and see what happens. will wd.Documents.Add cause the same "Automation error Library not registered"?

because u are using

Dim wd        As New Word.Application

and that could be the problem.

its the same with "flash" it works only if I make it dynamically using: Set Flash = Controls.Add("ShockwaveFlash.ShockwaveFlash", "Flash")
if I add it to the components, it will cause issues in IDE. so maybe u need to create word from CreateObject

if u check SamOscarBrown example, he also use CreateObject

----------


## AccessShell

Baka,  in your new code, it does NOT give any errors.  Thanks

I will try to modify my original code!

----------


## AccessShell

Baka,  I have integrated your code into my program.  When the word is *INcorrect*, the program works correctly.  It even gives a list of suggestions.

If you refer to post #13 above, and look at what happens when the word is correct.  The program correctly identifies the word as correct.  However, when it tries to get a list of synonyms and antonyms, it crashes again with the same error as before 
"Automation error Library not registered".

----------


## AccessShell

This is the new code


```
    If Not wd.CheckSpelling(strBuffer) Then        txtMain.ForeColor = vbRed
        lblMsg.Caption = "Spelling Incorrect!"
        lblMsg.ForeColor = vbRed
        Set wdsp = wd.GetSpellingSuggestions(strBuffer)
        lblSugs.Caption = NUM_OF_SUGS & CStr(wdsp.Count)
        
        For i = 1 To wdsp.Count
            lstSuggestions.AddItem wdsp(i).Name
        Next i
        '**********************************************************************
        'NOTE:  Incorrect spelling works great ==>  gives a list of suggestions
        '**********************************************************************
    Else
        lblMsg.Caption = "Spelling OK"
        lblMsg.ForeColor = vbBlue
        varBuffer = CVar(strBuffer)
        
        'Get the Synonyms
        Set wdsp = wd.GetSpellingSuggestions(strBuffer)
        synFound = SynonymInfo(Word:=varBuffer, LanguageID:=wdEnglishUS).Found
        'NOTE:  Now it dies on the previous line
        If synFound = True Then
            synList = SynonymInfo(Word:=varBuffer, LanguageID:=wdEnglishUS).SynonymList(Meaning:=1)
            For i = 1 To UBound(synList)
                lstSynonyms.AddItem synList(i)
            Next i
            lblSyns.Caption = NUM_OF_SYNS & CStr(UBound(synList))
        End If
        
        'Get the Antonyms
        'antList = SynonymInfo(Word:=varBuffer, LanguageID:=wdEnglishUS).AntonymList
        antList = SynonymInfo(varBuffer, wdEnglishUS).AntonymList
        For i = 1 To UBound(antList)
            lstAntonyms.AddItem antList(i)
        Next i
        lblAnts.Caption = NUM_OF_ANTS & CStr(UBound(antList))
    End If
    
    txtMain.ForeColor = vbBlack
    frmMain.MousePointer = vbDefault
    cmdCheck.Enabled = True
    cmdQuit.Enabled = True
```

----------


## SamOscarBrown

Not sure what is going on....but here is what I am now using for Spell checking...I have MS Word 2007 (has always been my favorite even though I used 2013 for a while, and will NEVER use 365!).  I have no issues with it finding that words are correct when they are not. (or vice-versa)..give this a try and see...

Sam

SPELLCHECK_Example.zip

----------


## AccessShell

SamOscarBrown, I cannot open your code in VB6.  I keep getting "Path not found"  C:\My VB6

----------


## SamOscarBrown

?  Not sure ?  I have no hardcoded paths

----------


## AccessShell

SamOscarBrown   Is this code you sent me


```
Private Sub Form_Load()strSearch = "Select * from myTitle"
Adodc1.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " & App.Path & "\churchcalendars.accdb;Persist Security Info=False;"
'adodc1.Recordset.DataSource
Adodc1.RecordSource = strSearch
'MsgBox Adodc1.Recordset.RecordCount
Adodc1.Refresh


End Sub
```

----------


## SamOscarBrown

No...at least not in this thread...

Here it is again (without a Form1.Log file).

Sammi

SPELLCHECK_Example_13Jan23.zip

----------


## AccessShell

Sam I got the same code

----------


## SamOscarBrown

THIS???

Private Sub Form_Load()strSearch = "Select * from myTitle"
Adodc1.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " & *App.Path* & "\churchcalendars.accdb;Persist Security Info=False;"
'adodc1.Recordset.DataSource
Adodc1.RecordSource = strSearch
'MsgBox Adodc1.Recordset.RecordCount
Adodc1.Refresh


End Sub

----------


## SamOscarBrown

Sorry...saved to wrong directory...stand by!

SPELLCHECK_Example.zip

----------


## SamOscarBrown

How's that?  NO idea where that code came from (one of my many other little projects, but not sure why it was included in that zip file---I didn't see it anywhere).  Anyway, download and unzip that last one and let me know...if you still get that 'connection' code...I am at a complete loss!

Sam

----------


## AccessShell

OK.  I got different code.  I need to analyze it.  BUT, It does not do what I need.

I can get incorrect word with suggestions.  I can get correct words, but I cannot get antonyms and synonyms as I I did on previous version of Windows, or my friends WIN10 laptop with the original WIn XP VB6 code.

----------


## SamOscarBrown

OH...you want a THESAURUS!

Why didn't you ask?

----------


## SamOscarBrown

Play with this....make sure (in your testing) to have ONLY the main form running when you use the Thesaurus, so you can see the popup from which to make choices.  Make sure you SELECT some text in the textbox after you type it in.

You can implement this into a program to check for synonyms from other form controls (like listbox, textbox, etc, etc).

spellcheck.zip

----------


## AccessShell

Many times in this thread I made mention of synonyms and antonyms.  Look at post #13

----------


## AccessShell

I changed the reference to "Microsoft Word 11.0 Object Library" from Word 14.  I use Office Pro 2003.
The program crashes in statement 

```
Set objWord = CreateObject("word.application")
```

 in  "Private Sub imgThesaurus_Click()" with 
"Err.Number      = 0 Err.Number      = 0"

----------


## SamOscarBrown

Anyway.....outa here.

----------


## AccessShell

I will say again.  The code I posted above in #13 works perfectly in WIN XP, WIN 7 and my WIN 10 laptop (VB6 not installed) .  It does not work on my WIN 10 Home.  All four computers have MS Office 2003 pro installed. 

I do not believe it is the program.  I don't know where else to look.  Maybe it is not a VB6 issue.  Where else can I look?

----------


## OptionBase1

Try adding a:



```
MsgBox wd.Version
```

In your code somewhere after your wd variable has been properly initialized but before the problematic code and see what you get from each of your devices when ran.  If they all say 11.0 (which means Office/Word 2003), then that would at least rule out that there is some versioning conflict on the non-working device.

----------

