Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-14-2015, 10:09 AM
gloos gloos is offline Select the whole sentence when a word has been modified Windows XP Select the whole sentence when a word has been modified Office 2007
Novice
Select the whole sentence when a word has been modified
 
Join Date: Apr 2015
Posts: 1
gloos is on a distinguished road
Default Select the whole sentence when a word has been modified


Hello,

I currently use the macro below to give me the number of added words when looking at a document with track changes. I would also like to return the number of words in this sentence. How can I do that? Thank you!

HTML Code:
Sub GetTCStats()
Dim lInsertsWords As Long
Dim lInsertsChar As Long
Dim lDeletesWords As Long
Dim lDeletesChar As Long
Dim sTemp As String
Dim oRevision As Revision
lInsertsWords = 0
lInsertsChar = 0
lDeletesWords = 0
lDeletesChar = 0
For Each oRevision In ActiveDocument.Revisions
Select Case oRevision.Type
Case wdRevisionInsert
lInsertsChar = lInsertsChar + Len(oRevision.Range.Text)
lInsertsWords = lInsertsWords + oRevision.Range.Words.Count
Case wdRevisionDelete
lDeletesChar = lDeletesChar + Len(oRevision.Range.Text)
lDeletesWords = lDeletesWords + oRevision.Range.Words.Count
End Select
Next oRevision
sTemp = "Insertions" & vbCrLf
sTemp = sTemp & " Words: " & lInsertsWords & vbCrLf
sTemp = sTemp & " Characters: " & lInsertsChar & vbCrLf
sTemp = sTemp & "Deletions" & vbCrLf
sTemp = sTemp & " Words: " & lDeletesWords & vbCrLf
sTemp = sTemp & " Characters: " & lDeletesChar & vbCrLf
MsgBox sTemp
End Sub
Reply With Quote
  #2  
Old 04-14-2015, 10:24 PM
gmayor's Avatar
gmayor gmayor is offline Select the whole sentence when a word has been modified Windows 7 64bit Select the whole sentence when a word has been modified Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Return it where? If you mean add it to the end of the document, then add a boolean variable declaration DIM bRevision as Boolean and replace the message box with

Code:
    bRevision = ActiveDocument.TrackRevisions
    ActiveDocument.TrackRevisions = False
    ActiveDocument.Range.InsertAfter vbCr & sTemp
    ActiveDocument.TrackRevisions = bRevision
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Select the whole sentence when a word has been modified Delete does not bring second sentence closer to first sentence Andoheb Word 29 07-03-2014 01:48 PM
Select the whole sentence when a word has been modified First word of sentence IF and then awolf Word VBA 7 03-16-2014 02:40 PM
Append text to a sentence containing specific word dgp Word VBA 3 02-28-2014 10:38 PM
Modified Signature Line in Microsoft Word gurp99 Word 0 03-28-2012 09:58 AM
I want to lock a sentence in Word smorkette Word 1 02-06-2010 12:57 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:45 PM.


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