Share via

VBA code

Anonymous
2025-02-05T13:32:09+00:00

How do I obtain a VBA code to be able to discount all tables, boxes and diagrams in my PhD thesis word count? Thanks

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Paul Edstein 82,861 Reputation points Volunteer Moderator
    2025-02-05T21:21:53+00:00

    Word's NUMWORDS field already omits any content in textboxes, diagrams, headers, footers, footnotes & endnotes. Table content is counted, however - unless the table is in a textbox. Words in your table of contents & bibliography will also be counted by the NUMWORDS field.

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments
  2. Paul Edstein 82,861 Reputation points Volunteer Moderator
    2025-02-06T07:04:23+00:00

    Try the following:

    Sub WordCount() 
    
    Dim i As Long, b As Long, c As Long, t As Long 
    
    With ActiveDocument 
    
      For i = 1 To .Tables.Count 
    
        t = t + .Tables(i).Range.ComputeStatistics(wdStatisticWords) 
    
      Next 
    
      For i = .Fields.Count To 1 Step -1 
    
        If .Fields(i).Type = wdFieldBibliography Then b = .Fields(i).Result.ComputeStatistics(wdStatisticWords): Exit For 
    
      Next 
    
       If .TablesOfContents.Count = 1 Then c = .TablesOfContents(1).Range.ComputeStatistics(wdStatisticWords) 
    
      i = 0: If .Indexes.Count = 1 Then i = .Indexes(1).Range.ComputeStatistics(wdStatisticWords) 
    
      MsgBox "There are " & .Range.ComputeStatistics(wdStatisticWords) & " words in the document body, including:" & vbCr & _ 
    
        c & " words in the Table of Contents;" & vbCr & _ 
    
        t & " words in tables;" & vbCr & _ 
    
        i & " words in the Index; and" & vbCr & _ 
    
        b & " words in the Bibliography." 
    
    End With 
    
    End Sub
    

    Note: The macro assumes you're using Word's built-in Table of Contents, Index and Bibliography tools, not 3rd-party products for these. Content in headers, footers, endnotes, footnotes, and shape-like objects in the document body is not counted.

    For PC macro installation & usage instructions, see: http://www.gmayor.com/installing\_macro.htm

    For Mac macro installation & usage instructions, see: https://wordmvp.com/Mac/InstallMacro.html

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  3. Charles Kenyon 167.8K Reputation points Volunteer Moderator
    2025-02-05T17:15:32+00:00

    How do I obtain a VBA code to be able to discount all tables, boxes and diagrams in my PhD thesis word count? Thanks

    Discount?

    Remove from the Word count all Tables, Text Boxes, and Diagrams in your thesis?

    You could write the code or find someone to do it for you.

    How much do these add to your Word count?

    Was this answer helpful?

    0 comments No comments