Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #7  
Old 10-29-2014, 10:29 PM
gmayor's Avatar
gmayor gmayor is offline How can I tag and selectively extract text (multiple files)? Windows 7 64bit How can I tag and selectively extract text (multiple files)? Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,142
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

I saw this question earlier, but couldn't find it when I returned to reply, and assumed it was in another forum that was down at the time. However I had worked out a simple macro solution that should do what you ask.

The following will count the words in paragraphs that start with a time in square brackets as shown followed by two or more initials. The result is displayed in a message box. When the macro is run the input box is not case sensitive.

Code:
Option Explicit
Sub WordsFromSpeaker()
Dim oRng As Range
Dim oPara As Paragraph
Dim strSpeaker As String
Dim strFirstWord As String
Dim lng_speaker As Long
Dim lng_Count As Long
    lng_Count = 0
    strSpeaker = UCase(InputBox("Enter speaker's initials", "Count Words", "LW"))
    For Each oPara In ActiveDocument.Paragraphs
        strFirstWord = ""
        Set oRng = oPara.Range
        oRng.MoveStartUntil "]"
        oRng.Start = oRng.Start + 1
        oRng.Collapse 1
        oRng.MoveEndUntil Chr(32)
        If Trim(oRng.Text) = Trim(strSpeaker) Then
            Set oRng = oPara.Range
            oRng.MoveStartUntil "]"
            oRng.Start = oRng.Start + Len(strSpeaker) + 2
            oRng.End = oRng.End - 1
             lng_Count = lng_Count + CountWords(oRng.Text)
        End If
    Next oPara
    MsgBox strSpeaker & Chr(32) & lng_Count & " words"
End Sub

Private Function CountWords(strText As String) As Long
Dim vWords As Variant
Dim strFirst As String
Dim i As Long
    vWords = Split(strText)
    For i = LBound(vWords) To UBound(vWords)
        strFirst = UCase$(Left$(vWords(i), 1))
        If strFirst Like "[A-Z]" Then
            CountWords = CountWords + 1
        End If
    Next i
End Function
__________________
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
 

Tags
format style, transcriptions, word count by speaker



Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I tag and selectively extract text (multiple files)? how to selectively highlight text in word cnyoon2 Word 1 08-04-2015 08:16 AM
How can I tag and selectively extract text (multiple files)? Importing multiple text files and getting certain figures. X82 Excel Programming 1 09-26-2012 09:29 PM
How can I tag and selectively extract text (multiple files)? VBA code to extract specific bookmarks from multiple word files Rattykins Word VBA 4 06-27-2012 10:02 PM
How can I tag and selectively extract text (multiple files)? how to extract wav files from ppts t-4-2 PowerPoint 2 01-19-2012 02:24 AM
How can I tag and selectively extract text (multiple files)? Copying multiple files as text without extensions Metamag Office 3 05-09-2011 06:25 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:08 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