Results 1 to 6 of 6

Thread: Use MS Word Thesaurus from VB application

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    266

    Question Use MS Word Thesaurus from VB application

    Hi,

    I want to know how to use MS Word in-build Thesaurus from VB application. My situations are like below,

    1. Open a .doc document from VB application.
    2. If I double-click on a word then rest of the similar word will be highlighted and curved through [].
    eg. I select on the word 'easy', then it highlighted all 'easy' in the document and curved as ['easy']
    3. If I select from the option that "20% word will be highlighted" then randomly 20% word of the document will be highlighted.
    4. If I press Replace button then it will replaced the highlighted words with SYNONYMS from the build-in Thesaurus of MS Word.

    Please help me. Thank you in advance.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Use MS Word Thesaurus from VB application

    Try
    Code:
    Private objWord As Word.Application
    Private objDoc  As Document
    Private strText As String
    
    Private Sub Command1_Click()
        On Error GoTo ErrorTrap
        'the word in question must be hightlighted, otherwise
        'we dont know what we are looking for
        MsgBox "No word selected.  Hightlight desired word please."
        If Text1.SelText = vbNullString Then Exit Sub
        ' Start and hide Word.  If word is actually showing, then
        'they will know how we do our magic
        Set objWord = CreateObject("word.application")
        objWord.Visible = False
        objWord.WindowState = wdWindowStateMinimize
        ' Create a new Word document.
        Set objDoc = objWord.Documents.Add
        ' Set the Word document's range to the selected text and
        'call the thesaurus.
        objDoc.Range = Text1.SelText
        objDoc.Range.CheckSynonyms
        ' Replace the text with the selected synonym.
        strText = objDoc.Range
        strText = Left$(strText, Len(strText) - 1)
        Text1.SelText = strText
        Exit Sub
    ErrorTrap:
        MsgBox Err & " " & Error
    End Sub
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    On Error Resume Next
    objDoc.Close savechanges:=wdDoNotSaveChanges
    objWord.Quit savechanges:=wdDoNotSaveChanges
    Set objWord = Nothing
    Set objDoc = Nothing
    End Sub

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    266

    Thumbs up Re: Use MS Word Thesaurus from VB application

    Respected Sir,

    Thanks a lot for the help. Its working. But I may need to ask you some question regarding the same purpose. Then I resolved the thread.

    Let me know if I able to help you anyway.

    Regards.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Use MS Word Thesaurus from VB application

    Quote Originally Posted by systech44
    Respected Sir,

    Thanks a lot for the help. Its working. But I may need to ask you some question regarding the same purpose. Then I resolved the thread.

    Let me know if I able to help you anyway.

    Regards.
    What? I don't understand.

    I'm not the one that needs help. Are you still having a problem?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    266

    Smile Re: Use MS Word Thesaurus from VB application

    I mean your code is working. I may need to ask you few question on the basis of the code and its understanding in near future. Thats it. Thanks.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Use MS Word Thesaurus from VB application

    Quote Originally Posted by systech44
    I mean your code is working. I may need to ask you few question on the basis of the code and its understanding in near future. Thats it. Thanks.
    Go ahead and ask.

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