![]() |
|
#7
|
||||
|
||||
|
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 |
| Tags |
| format style, transcriptions, word count by speaker |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
how to selectively highlight text in word
|
cnyoon2 | Word | 1 | 08-04-2015 08:16 AM |
Importing multiple text files and getting certain figures.
|
X82 | Excel Programming | 1 | 09-26-2012 09:29 PM |
VBA code to extract specific bookmarks from multiple word files
|
Rattykins | Word VBA | 4 | 06-27-2012 10:02 PM |
how to extract wav files from ppts
|
t-4-2 | PowerPoint | 2 | 01-19-2012 02:24 AM |
Copying multiple files as text without extensions
|
Metamag | Office | 3 | 05-09-2011 06:25 PM |