Macro to count word counts in different Word docs, and enter them into Excel?

Ripley2453

New Member
Joined
Nov 25, 2015
Messages
12
Hi everyone,

I'm an aspiring author, and want to keep track of the word counts in my chapters.
At the moment each chapter is a different file. I would like a macro to go into each file, and tell me the word count in an excel table, for each chapter.

I'm usually pretty good at figuring macros out for myself, but I would just like a nice, simple macro that I can just copy and paste.

Anyone able to help me?

NOTE: I am using Office 2016 (365).

Cheers,
Brad.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
You do realise Word can give its own word count in a given file? Usually on the status bar or, if you prefer, in a NUMWORDS field in the document.
 
Upvote 0
Hi Macropod, thanks for your reply.

I am aware of that, but I have a lot of chapters saved in different files.
I want to have an excel table with all the wordcounts for each chapter, so I can keep a tally of my total novel wordcount.

Hope that makes sense,
Cheers.
 
Upvote 0
Seems overkill, but you could use an Excel macro like:
Code:
Sub GetDocumentWordCounts()
 'Note: this code requires a reference to the Word object model
Application.ScreenUpdating = False
Dim wdApp As New Word.Application
Dim wdDoc As Word.Document
Dim strFolder As String, strFile As String
Dim WkSht As Worksheet, i As Long
strFolder = GetFolder
If strFolder = "" Then Exit Sub
Set WkSht = ActiveSheet
i = 0
strFile = Dir(strFolder & "\*.docx", vbNormal)
While strFile <> ""
  i = i + 1
  Set wdDoc = wdApp.Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
  WkSht.Cells(i, 1) = strFile
  WkSht.Cells(i, 2) = wdDoc.ComputeStatistics(wdStatisticWords)
  wdDoc.Close SaveChanges:=False
  strFile = Dir()
Wend
wdApp.Quit
Set wdDoc = Nothing: Set wdApp = Nothing: Set WkSht = Nothing
Application.ScreenUpdating = True
End Sub

Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
Simply run the macro, select the folder then wait a moment while the workbook gets populated.
 
Upvote 0
No worries, I love a good macro!

Cheers mate, I'll try this when I'm home after work.
I'll let you know how it goes :)
 
Upvote 0
It's coming back with a compile error, highlighting this specific section:

'Dim wdApp As New Word.Application'

It then says 'User-defined type not defined'

Am I missing something? :confused:
 
Upvote 0
This has nothing to do with the individual Word files, but concerns the Word application. You set the reference via Tools|References in the VBE, scrolling down till you find the Microsoft Word library.
 
Upvote 0
This has nothing to do with the individual Word files, but concerns the Word application. You set the reference via Tools|References in the VBE, scrolling down till you find the Microsoft Word library.


Thank you, I'll give that a try.
I've never interlinked office applications via VBA before, so I wasn't aware. :laugh:

Cheers!
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top