NumWords Property

Returns the number of words in the recognized text. Read-only Long.


*expression   * Required. An expression that returns a Layout object.


The NumWords property returns the number of words recognized by optical character recognition (OCR). If NumWords is zero (0), the page does not contain text or the OCR engine has failed to find any text on the page.

In East Asian languages, each character also counts as a word. As a result, in recognized text consisting exclusively of East Asian characters, the NumChars and NumWords properties return the same value.


The following example loads a document, performs OCR on the first page, and then displays information, including the number of words, about the page's OCR layout.

Sub TestLayoutProperties()

  Dim miDoc As MODI.Document
  Dim miLayout As MODI.Layout
  Dim strLayoutInfo As String
  Set miDoc = New MODI.Document
  miDoc.Create "C:\document1.tif"
  Set miLayout = miDoc.Images(0).Layout
  strLayoutInfo = _
    "Language: " & miLayout.Language & vbCrLf & _
    "Number of characters: " & miLayout.NumChars & vbCrLf & _
    "Number of fonts: " & miLayout.NumFonts & vbCrLf & _
    "Number of words: " & miLayout.NumWords & vbCrLf & _
    "Beginning of text: " & Left(miLayout.Text, 50) & vbCrLf & _
    "First word of text: " & miLayout.Words(0).Text
  MsgBox strLayoutInfo, vbInformation + vbOKOnly, _
    "Layout Information"
  Set miLayout = Nothing
  Set miDoc = Nothing

End Sub

Applies to | Layout Object