Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use the Spell checker from Word in a VB ap

Status
Not open for further replies.

jeepxo

Programmer
Oct 1, 2002
228
CA
Not sure if I can do this or not, and I don't have the Office SDK to find the answer.

Here is my scenario.
We have a VB application that has various user inputs. The users have now asked if I can add a spell checker for them so that their reports have less spelling mistakes in them.

I am on a shoe string budget for this project, so I am trying use what I know will be on the clients machines. I know that they will all have Word 97. I know that word 97 has a spell checker in it.

Does anyone have an idea on whether I could "steal" (for lack of a better word) the spell checker in it to use for this ap?

I'm thinking I should be able to create a word ap within the VB Ap, then basically say something along the lines of wordap.dictionary.spellcheck(someword) to check if the word is in the dictionary. Where I see the problem though, is defining which dictionary to use.

So if any of you guys out there happens to have the Office SDK would you mind looking it up for me and telling me what path I need to head down to use the spell checker from Word.
 
Think I found it myself

Private Sub Command1_Click ()
Dim oWDBasic As Object
Dim sTmpString As String
Set oWDBasic = CreateObject("Word.Basic")
oWDBasic.FileNew
oWDBasic.Insert Text1.Text
On Error Resume Next
oWDBasic.ToolsSpelling
oWDBasic.EditSelectAll
oWDBasic.SetDocumentVar "MyVar", oWDBasic.Selection
sTmpString = oWDBasic.GetDocumentVar("MyVar")
Text1.Text = Left(sTmpString, Len(sTmpString) - 1)
MsgBox "Spell Check is complete"
End Sub
 
Well that example does check the spelling, however, once you correct a spelling mistake it opens a Word document with the correction in it.

Anyone familiar with this? Any idea how I can keep it from making the word doc visible?
My preference would be for the dictionary prompt to open with the choices, then when you make your correction the dictionary prompt goes away and it continues checking the spelling in the background.
 
I have found that if I change the function slightly

sTmpString = oWDBasic.GetDocumentVar("MyVar")
oWDBasic.FileExit 2 <----------------- added this
Text1.Text = Left(sTmpString, Len(sTmpString) - 1)
MsgBox &quot;Spell Check is complete&quot;

it will flash the word doc, then close it for me, but I am still not able to avoid showing the word doc when it finds an error
 
you could try something like this

Code:
Option Explicit

Private moMSWord As Object

Private Sub Command1_Click()
  If moMSWord.CheckSpelling(Text1.Text) Then
    MsgBox &quot;OK&quot;, vbInformation
  Else
    Text1.SetFocus
    MsgBox &quot;Incorrect&quot;, vbExclamation
  End If
End Sub

Private Sub Form_Load()
  Set moMSWord = CreateObject(&quot;Word.Application&quot;)
End Sub

Private Sub Form_Unload(Cancel As Integer)
  moMSWord.Quit 0 ' wdDoNotSaveChanges = 0
  Set moMSWord = Nothing
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top