PDA

View Full Version : [SOLVED:] Count words with VBA



Gasman
07-02-2021, 04:32 AM
Hi all,
Someone asked on another forum if they could count words in Access as is shown in Word in the status bar.?

Besides using Split(), I was thinking, you could use Word to do it?

So I pasted some text and then used ActiveDocument.Words.Count to display the count, which was 75, yet the status bar shows words as 69.

This was a new document and a simple copy and paste.

What could cause the discrepancy?

TIA

Edit: A Split() on a single space actually produces 69 ? Ubound being 68.

Gasman
07-02-2021, 05:14 AM
Found out why.

Need to use ActiveDocument.Range.ComputeStatistics(wdStatisticWords) to get matching number to status bar

https://support.microsoft.com/en-us/topic/word-count-appears-inaccurate-when-you-use-the-vba-words-property-835c0cd8-3bff-50d0-b6ea-9da4ca22e3ff