Word VBA: Counting Documents

The following Word VBA macro shows a message box with the count of documents.

Macro Example

Sub GetDocumentsCount()
 
  MsgBox Documents.Count

End Sub

Description

[Application.]Documents

Documents...

The [Application.]Documents property returns a Documents collection object.

obj-Word-Application-Documents

The Documents is a collection of all the Document objects those are currently open in Word.

And, the Documents property is a member of the Word.Global class, so we can omit the Application property.

obj-Word-Documents

Document.Count

  Documents.Count

The Docments.Count property returns a Long integer value that represents the number of documents.

obj-Word-Documents-Count

And the code: Document.Count is set to the parameter of a MsgBox function.
So, a message box shows the count of Word documents.

Sub GetDocumentsCount()
 
  MsgBox Documents.Count

End Sub

Properties

http://www.relief.jp/itnote/archives/word-vba-getting-documents-count.php

Apply To

  • Word 2013
  • Word 2010
  • Word 2007