Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #11  
Old 01-22-2017, 08:09 AM
gmaxey gmaxey is offline Count words between quotation marks Windows 7 32bit Count words between quotation marks Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

sojiro,

Paul knows this but since you didn't inquire about it he may have left it unsaid to keep from complicating things. However, if your documents are more that just simple text (e.g. they have endnotes, footnotes, textboxes, etc.) it is a bit more involved to get a total count and even then "total" is rather elusive ;-).

Add a footnote to your text and run Paul's code. You will see that the count of words in the footnotes are not included in either the total or quoted word count. Try with this:

Code:
Public Sub Demo()
Dim oRng As Word.Range
Dim lngValidator As Long
Dim oShp As Shape
Dim lngWordsInQoutes As Long, lngWords As Long, bSvd As Boolean
  Application.ScreenUpdating = False
  bSvd = ActiveDocument.Saved
  'Fix any skipped blank Header/Footer issue
  lngValidator = ActiveDocument.Sections(1).Headers(1).Range.StoryType
  'Iterate through document story ranges
  For Each oRng In ActiveDocument.StoryRanges
    If oRng.StoryType < 12 Then
    'Iterate through all linked stories
    Do
      lngWords = lngWords + oRng.ComputeStatistics(wdStatisticWords)
      lngWordsInQoutes = lngWordsInQoutes + fcnCountInQuotes(oRng)
      On Error Resume Next
      Select Case oRng.StoryType
        Case 6, 7, 8, 9, 10, 11
          If oRng.ShapeRange.Count > 0 Then
            For Each oShp In oRng.ShapeRange
              If Not oShp.TextFrame.TextRange Is Nothing Then
                lngWordsInQoutes = lngWordsInQoutes + fcnCountInQuotes(oShp.TextFrame.TextRange)
              End If
            Next
          End If
        Case Else
          'Do Nothing
      End Select
      On Error GoTo 0
      'Get next linked story (if any)
      Set oRng = oRng.NextStoryRange
    Loop Until oRng Is Nothing
    End If
  Next
  MsgBox "This document contains " & lngWords & " words ," & vbCr & _
      "of which " & lngWordsInQoutes & " (" & Format(lngWordsInQoutes * 100 / lngWords, "0.00") & _
      "%) are in quotes."
  ActiveDocument.Saved = bSvd
lbl_Exit:
  Exit Sub
End Sub
Function fcnCountInQuotes(ByVal oRng As Word.Range) As Long
  With oRng.Find
    .ClearFormatting
    .Text = "[“" & Chr(34) & "]*[" & Chr(34) & "”]"
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    While .Execute
      fcnCountInQuotes = fcnCountInQuotes + oRng.ComputeStatistics(wdStatisticWords)
      oRng.Collapse wdCollapseEnd
    Wend
  End With
lbl_Exit:
  Exit Function
End Function
Then add a few words in a header or footer. Two words in the header of a 1 page document = 2 words. Two words in the header of a 1000 page document = 2 words.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Straight Vs Curly Quotation Marks FOsmund Word 4 04-16-2015 01:48 PM
Quotation marks are inserted in wrong font sinz54 Word 5 01-11-2015 06:34 PM
Can't find space before closing quotation marks wardw Word 7 01-16-2014 12:13 PM
How do I select everything that is in quotation marks? Jophassa Word 4 09-02-2011 10:57 AM
Count words between quotation marks problem with automatic formatting on quotation marks Bobosmite Word 3 05-27-2010 07:06 PM

Other Forums: Access Forums

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