Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 12-03-2018, 07:47 PM
macropod's Avatar
macropod macropod is offline How to count words in a text, arrange them in separate lines and put the grammar class ? Windows 7 64bit How to count words in a text, arrange them in separate lines and put the grammar class ? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,514
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Word is incapable of the context analysis needed to determine the part of speech for many words. For example, with your sample text, the following macro reports the potential parts of speech of most words - note the common exceptions!
Code:
Sub PartsOfSpeech()
Dim wdSynInfo As SynonymInfo, wdSynList As Variant, i As Long, w As Long
Dim wdSyn As String, StrWrd As String, StrTmp As String, StrOut As String
With ActiveDocument.Range
  For w = 1 To .Words.Count
    StrTmp = "": StrWrd = Trim(.Words(w))
    If StrWrd Like "[A-Za-z]*" Then
      Set wdSynInfo = SynonymInfo(Word:=StrWrd, LanguageID:=wdEnglishUS)
      If wdSynInfo.MeaningCount <> 0 Then
        wdSynList = wdSynInfo.PartOfSpeechList
        For i = 1 To UBound(wdSynList)
          Select Case wdSynList(i)
            Case wdAdjective: wdSyn = "adjective"
            Case wdNoun: wdSyn = "noun"
            Case wdAdverb: wdSyn = "adverb"
            Case wdVerb: wdSyn = "verb"
            Case wdConjunction: wdSyn = "conjunction"
            Case wdIdiom: wdSyn = "idiom"
            Case wdInterjection: wdSyn = "interjection"
            Case wdPreposition: wdSyn = "preposition"
            Case wdPronoun: wdSyn = "pronoun"
            Case Else: wdSyn = "other"
          End Select
          If UBound(Split(StrTmp, " ")) < 1 Then
            StrTmp = StrTmp & " " & wdSyn
          ElseIf Split(StrTmp, " ")(UBound(Split(StrTmp, " "))) <> wdSyn Then
            StrTmp = StrTmp & " " & wdSyn
          End If
        Next i
        StrOut = StrOut & vbCr & StrWrd & ": " & Replace(Trim(StrTmp), " ", ", ")
      Else
        StrOut = StrOut & vbCr & StrWrd & ": No meanings found."
      End If
    End If
  Next w
End With
MsgBox StrOut
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting grammar check to ignore spacing associated with numbers but not with words grrlwhit03 Word 0 06-20-2017 04:51 PM
How to count words in a text, arrange them in separate lines and put the grammar class ? Putting separate words together mohsen.amiri Word 1 10-27-2016 12:34 AM
How to Re-arrange large field lines in talble PRA007 Word Tables 4 03-18-2015 02:24 AM
Separate lines in an Excel cell - possible? If so, how? mtcn Excel 5 12-12-2014 01:06 PM
How to count words in a text, arrange them in separate lines and put the grammar class ? Creating Text to count words WITHOUT title page ingmar.s Word 3 10-08-2009 10:23 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:58 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft