Aanmelden met Microsoft
Meld u aan of maak een account.
Hallo,
Selecteer een ander account.
U hebt meerdere accounts
Kies het account waarmee u zich wilt aanmelden.
Engels
Dit artikel is niet beschikbaar in uw taal.

For a Microsoft Word 97 version of this article, see 159791.

For a Microsoft Word 98 Macintosh Edition version of this article, see 183870.

For a Microsoft Word 2000 version of this article, see 212705.

When you use the Microsoft Visual Basic for Applications (VBA) Words property to return a word count in a Microsoft Word document, the number of words returned appears to be inaccurate.

Symptoms

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. For more information, click the following article number to view the article in the Microsoft Knowledge Base:

290140 How to run the sample code for the Office XP programs from Knowledge Base articles

The Words property returns a collection that represents all the words in a range, selection, or document. The collection includes all punctuation and paragraph marks in the selection or the document.

For example, if you attempt to determine the word count in the following three lines of text

This is x number of words.
This is x number of words.
This is x number of words.
by using the Words property as follows

Sub GetWords()

MsgBox ActiveDocument.Words.Count

End Sub

the result is 24 words.

Cause

To return only the number of words in a document or a range, excluding paragraph marks and punctuation, use the ComputeStatistics method instead of the Words property.

The ComputeStatistics method returns a word count that does not include paragraph marks or punctuation. By using the sample text from the "Cause" section, the following ComputeStatistics method code returns a count of 18 words:

Sub GetWords()

MsgBox ActiveDocument.Range.ComputeStatistics(wdStatisticWords)

End Sub

For more information, click the following article number to view the article in the Microsoft Knowledge Base:

241333 Word count macro available to count words in a selection

For more information about how to get help with Visual Basic for Applications, click the following article number to view the article in the Microsoft Knowledge Base:

226118 List of resources that are available to help you learn Visual Basic for Applications programming

Workaround

Meer hulp nodig?

Meer opties?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Was deze informatie nuttig?

Wat heeft uw ervaring beïnvloed?
Als u op Verzenden klikt, wordt uw feedback gebruikt om producten en services van Microsoft te verbeteren. Uw IT-beheerder kan deze gegevens verzamelen. Privacyverklaring.

Hartelijk dank voor uw feedback.

×