4

I'm trying to find a way of listing the number of pages within multiple word documents, all saved within the same folder. Is this possible using VBA?

I am using:

  • Windows 7 and
  • Microsoft Office 2007
4
  • Please give us some more details; what version of Word? what have you already tried? Does it have to be VBA? If so, post some code you are working with.
    – CharlieRB
    Oct 17, 2013 at 11:22
  • I'm using Microsoft Office Word 2007. I haven't tried anything, my research has revealed some vba sub routines that are associated to this task but don't provide a solution. I specified VBA since I thought it would be possible to loop through all the necessary documents but don't have the expertise to produce any code like this.
    – RobN
    Oct 17, 2013 at 11:28
  • Would be good if you updated your question with the info you provided above, ie win office 2007 etc
    – Deesbek
    Oct 17, 2013 at 19:40
  • Thank Deesbek, I've added some further information regarding my system. I'll add this level of detail to future posts thanks for the advice.
    – RobN
    Oct 18, 2013 at 9:55

2 Answers 2

3

I don't know how to do it in VBA (in Word itself) but you could create a small VBS-file and drop it in the directory and double click it:

Const wdStatisticPages = 2
Set FSO = CreateObject("Scripting.FileSystemObject")
currentPath = fso.GetAbsolutePathName(".")
set FLD = FSO.GetFolder(currentPath)
Set objWord = CreateObject("Word.Application")
objWord.Visible = False
For Each Fil In FLD.Files
    If UCase(FSO.GetExtensionName(Fil.name)) = "DOCX" Then
        Set objDoc = objWord.Documents.Open(currentPath & "\" & Fil.Name)
        intPages = intPages + objDoc.ComputeStatistics(wdStatisticPages)
        objDoc.Saved = True
        objDoc.Close
    End If
Next
objWord.Quit
Wscript.Echo "Total pages: " & intPages
Set oShell = Nothing
Set FLD = Nothing
Set FSO = Nothing

Assuming the files are all .docx extension.

Inspiration (and explanation) came from here. For simplicity i didn't use objWMIService but just went with Scripting.FileSystemObject. You can also set objWord.Visible = False to True. You'll see the Word-application flickering on and off.

You can also show the pages in "Windows Explorer". Just right-click the columns above the files and choose more, you can select pages to show a column with the pages per Word-document. So you can see the page-count before opening the document. (You'll need to be in the Details-view to see the columns)

If you really want you could also translate this yourself to VBA (Word-macro).

1
  • Thank you so much Rik, you've now encouraged me to learn VBS!
    – RobN
    Oct 17, 2013 at 11:43
0

See my previous answer to a similar question - this may help.

It IS possible to achieve, technically, but not always reliable - especially without being (computationally) expensive, which nobody ever wants - and my answer explains why.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .