CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2001
    Posts
    9

    error using Word object for spell checking

    i have a form with a text box and a list box. when the user type in the text box, a list of word suggestion would display in the list box. I had set the reference to word object but errors still occur. the codes i used are as below:

    the error i received when i started typing in the textbox is "object variable or with block varilable not set"

    'name of listbox = lstCorrect
    'name of textbox =txt_ResFree

    in the module.bas:
    Public SC As Word.Application
    Public Doc As Document
    Public SpellErrors As SpellingSuggestions
    Public SpellError As SpellingSuggestion

    Public Sub Main()
    Set SC = New Word.Application
    SC.Visible = False
    Set Doc = SC.Documents.Open(AppPath& "Blank.doc")
    frmSpell.Show
    End Sub
    Public Function AppPath() As String
    Dim sAns As String
    sAns = App.Path
    If Right(App.Path, 1) <> "\" Then sAns = sAns & "\"
    AppPath = sAns
    End Function

    in the form:

    Private Sub txt_ResFree_Change()
    lstCorrect.Visible = True
    lstCorrect.Clear
    Set SpellErrors = SC.GetSpellingSuggestions(Word:=txt_ResFree.Text)
    If SpellErrors.Count > 0 Then
    For Each SpellError In SpellErrors
    lstCorrect.AddItem SpellError.Name
    Next SpellError
    ElseIf SC.CheckSpelling(Word:=txt_ResFree.Text) Then
    lstCorrect.AddItem txt_ResFree.Text
    End If
    End Sub

    Private Sub lstCorrect_DblClick()
    Dim sel As Integer
    Clipboard.Clear
    Clipboard.SetText lstCorrect.Text
    txt_ResFree.Text = lstCorrect.Text
    End Sub

    Please HELP!!..

    thanks


  2. #2
    Join Date
    Mar 2001
    Location
    Australia
    Posts
    146

    Re: error using Word object for spell checking

    Is your project set up to use Sub Main as the Startup Object?

    To check this go to the Project Menu -> Project Properties

    Go to the General tab and check the Startup Object. If it is set to frmSpell, you will need to change it to Sub Main, otherwise you won't be starting word and you will get the error you stated.

    Hope this helps,

    Nathan.

    PS I don't think you need to open the blank document to get the spell checker to work.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured