Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 04-16-2019, 09:54 PM
subrota subrota is offline Windows 10 Office 2013
Novice
 
Join Date: Apr 2019
Posts: 8
subrota is on a distinguished road
Default Synonym list

I want all synonyms with a list inside a text box in a user form for a word from a paragraph. But it shows one by one with the msgbox.





Code:
Private Sub CommandButton1_Click()

Dim mySynObj As Object
Dim SList As Variant
Dim i As Variant

Selection.MoveLeft Unit:=wdWord, Count:=1
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend




Set mySynObj = Selection.Range.SynonymInfo
SList = mySynObj.SynonymList(1)
For i = 1 To UBound(SList)
  MsgBox "A synonym for " & mySynObj.Word _
   & " is " & SList(i)
Next i
End Sub
Attached Files
File Type: docm Synonym List.docm (16.6 KB, 0 views)

Last edited by macropod; 04-16-2019 at 10:45 PM. Reason: Added code tags & formatting
Reply With Quote
  #2  
Old 04-16-2019, 10:50 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,355
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

That's a trivial, change. Really!
Code:
Private Sub CommandButton1_Click()

Dim mySynObj As Object
Dim SList As Variant
Dim i As Long
StrOut As String


Selection.MoveLeft Unit:=wdWord, Count:=1
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend




Set mySynObj = Selection.Range.SynonymInfo
SList = mySynObj.SynonymList(1)
For i = 1 To UBound(mySynObj.SynonymList(1))
  StrOut = StrOut & vbCr & SList(i)
Next i
MsgBox "Synonyms for " & mySynObj.Word & " are:" & StrOut
End Sub
PS: When posting code, please use the code tags, indicated by the # button on the posting menu, and structured code. Without both, your code loses much of whatever structure it had.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 04-16-2019, 11:29 PM
subrota subrota is offline Windows 10 Office 2013
Novice
 
Join Date: Apr 2019
Posts: 8
subrota is on a distinguished road
Default

Thanks a lot Edstein
It works perfectly. Thanks Again.
Reply With Quote
Reply

Tags
synonym list

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Task list checkboxes appear solid black when I print list mechitar Outlook 0 10-24-2018 09:06 AM
Attempting to mail merge one list into a document containing 3 pages - each page needs the same list LisaRH Mail Merge 3 08-09-2018 03:01 PM
How to import list from Excel into drop-down list into word ahw Word VBA 40 07-25-2018 02:58 PM
Word 2013 question - master list current list markecb Word 6 02-28-2016 01:51 AM
List Style Numbering picks up out of order number from LATER list spthomas Word 12 12-16-2013 05:23 PM


All times are GMT -7. The time now is 09:29 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft