|
-
Sep 21st, 2007, 03:25 AM
#1
Thread Starter
Hyperactive Member
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.
-
Sep 21st, 2007, 05:55 AM
#2
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
-
Sep 21st, 2007, 06:34 AM
#3
Thread Starter
Hyperactive Member
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.
-
Sep 21st, 2007, 06:38 AM
#4
Re: Use MS Word Thesaurus from VB application
 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?
-
Sep 22nd, 2007, 12:35 AM
#5
Thread Starter
Hyperactive Member
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.
-
Sep 24th, 2007, 10:27 AM
#6
Re: Use MS Word Thesaurus from VB application
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|