General discussion

  • Creator
    Topic
  • #2344714

    Character Count in MS Word

    Locked

    by terrent ·

    I’m writing an app in VB (not a macro) that will, among other things, count the characters in a Word (97 or 2000) document according to corporate specified parameters. These parameters are still being clarified, so I may need to adjust them and recompile for analysis. So far, it looks like the standard will be identical with what comes with Word (such as: returns are not counted while spaces are) except tabs should be counted as characters. How can this be done using the MS Word object in VB6?
    Thank you

All Comments

  • Author
    Replies
    • #3692540

      Character Count in MS Word

      by glen_mcleod ·

      In reply to Character Count in MS Word

      This code uses the internal Word counter:

      Function DocumentCharacters(ByVal sFile As String) As Long
      Dim oWord As Word.Application
      Dim oDoc As Word.Document

      Set oWord = New Word.Application
      Set oDoc = oWord.Documents.Open(sFile)

      DocumentCharacters = oDoc.Characters.Count

      oDoc.Close
      Set oDoc = Nothing
      Set oWord = Nothing
      End Function

      You have to set a reference to the Word object library in order to use the declarations “Word.Application” and “Word.Document”

      Glen

      • #3692497

        Character Count in MS Word

        by terrent ·

        In reply to Character Count in MS Word

        Ok, I got that. But the only changes in what gets counted are with or without spaces. I need to count tabs and possibly other stuff that MS doesn’t already count.
        Thanks anyway.

    • #3692538

      Character Count in MS Word

      by andrew ·

      In reply to Character Count in MS Word

      Try this:
      set a reference to the Word9 Object Library (MSWORD9.OLB)

      add this code:

      Dim oApp As Word.Application
      Dim oDoc As Word.Document
      Dim lChars As Long
      Set oApp = New Word.Application
      Set oDoc = oApp.Documents.Open(“c:\test.doc”)
      lChars = oDoc.ComputeStatistics(wdStatisticCharactersWithSpaces)
      MsgBox lChars

      • #3692498

        Character Count in MS Word

        by terrent ·

        In reply to Character Count in MS Word

        Ok, I got that. But the only changes in what gets counted are with or without spaces. I need to count tabs and possibly other stuff that MS doesn’t already count.
        Thanks anyway.

    • #3721489

      Character Count in MS Word

      by terrent ·

      In reply to Character Count in MS Word

      This question was closed by the author

Viewing 2 reply threads