Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #9  
Old 01-14-2011, 07:53 PM
macropod's Avatar
macropod macropod is offline How to get the number of words in the file (please see details)? Windows 7 32bit How to get the number of words in the file (please see details)? Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,342
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

Hi Jamal,

The following macro gives you a wide range of statistics
Code:
Sub CountWords()
Application.ScreenUpdating = False
Dim oTbl As Table, lTbl As Long, Sctn As Section
Dim oHdFt As HeaderFooter, lHdr As Long, lFtr As Long
Dim oEnt As Endnote, lEnt As Long
Dim oFnt As Footnote, lFnt As Long
Dim oShp As Shape, lShp As Long
Dim oPara As Paragraph, lCpt As Long
With ActiveDocument
  For Each oTbl In .Tables
    lTbl = lTbl + oTbl.Range.ComputeStatistics(wdStatisticWords)
  Next
  For Each oEnt In .Endnotes
    lEnt = lEnt + oEnt.Range.ComputeStatistics(wdStatisticWords)
  Next
  For Each oFnt In .Footnotes
    lFnt = lFnt + oFnt.Range.ComputeStatistics(wdStatisticWords)
  Next
  For Each Sctn In .Sections
    For Each oHdFt In Sctn.Headers
      If Not oHdFt.LinkToPrevious Then _
        lHdr = lHdr + oHdFt.Range.ComputeStatistics(wdStatisticWords)
    Next
    For Each oHdFt In Sctn.Footers
      If Not oHdFt.LinkToPrevious Then _
        lFtr = lFtr + oHdFt.Range.ComputeStatistics(wdStatisticWords)
    Next
  Next
  For Each oShp In .Endnotes
    If Not oShp.TextFrame Is Nothing Then _
      lShp = lShp + oShp.TextFrame.TextRange.ComputeStatistics(wdStatisticWords)
  Next
  For Each oPara In .Paragraphs
    If oPara.Style = "Caption" Then _
      lCpt = lCpt + oPara.Range.ComputeStatistics(wdStatisticWords)
  Next
  MsgBox "Word Count Statistics:" & vbCr & _
    "Tables - " & vbTab & vbTab & lTbl & vbCr & _
    "EndNotes - " & vbTab & lEnt & vbCr & _
    "Footnotes - " & vbTab & lFnt & vbCr & _
    "Headers - " & vbTab & vbTab & lHdr & vbCr & _
    "Footers - " & vbTab & vbTab & lFtr & vbCr & _
    "Shapes - " & vbTab & vbTab & lShp & vbCr & _
    "Captions - " & vbTab & lCpt & vbCr & _
    "Other - " & vbTab & vbTab & .Range.ComputeStatistics(wdStatisticWords) - lTbl - lCpt
End With
Application.ScreenUpdating = True
End Sub
I haven't included your "Words in the references page" stats, as I don't know how your document is laid out and, therefore, how those stats might best be defined in the vba code. Do note too that words in headers and footers aren't counted by Word anyway.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
When Printing a file Sources/Details included BigTunz Word 0 03-01-2010 01:24 AM
Hide contact details AndyKC Outlook 0 01-25-2010 11:00 PM
Transfer of account details to Outlook 2003 on Windows7 taralastair Outlook 1 01-04-2010 01:24 PM
Printing task details STEVEK Outlook 0 11-11-2009 06:02 AM
Entering Contact details GemmaD Outlook 0 12-18-2008 06:41 AM

Other Forums: Access Forums

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