Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2006

Tip: Looking for answers? Try searching our database.

Character count - VBA and Word

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Scott P - 23 Feb 2006 05:58 GMT
Hi,

I am trying to count the number of characters in a MS Word document.  My
document contains the text "Hello world." with a paragraph mark following the
text.  The "Word Count" feature within MS Word indicates that my document
contains 12 characters (with spaces).

The following VBA code applied to this document, however, indicates that my
document contains 13 characters:

Sub CharacterCode()

Dim lngChar As Long

lngChar = ActiveDocument.Characters.Count

Debug.Print "lngChar = " & lngChar

End Sub

Why is there a difference between these character count values and, perhaps
more specifically, why is VBA indicating that there is an extra character in
my document as compared in MS Word's native "Word Count" feature?

Thank you in advance for your input on this topic.
Jezebel - 23 Feb 2006 06:32 GMT
The difference is that VBA includes the paragraph mark. If you have tables
it will also include cell markers.

Try this to see what's happening --

   Dim pChar As Range
   For Each pChar In ActiveDocument.Characters
       Debug.Print Asc(pChar)
   Next

> Hi,
>
[quoted text clipped - 25 lines]
>
> Thank you in advance for your input on this topic.
Scott P - 24 Feb 2006 01:36 GMT
Thank you for your reply and help -- I appreciate the explanation regarding
the paragraph mark and cell markers and your providing the below code.

> The difference is that VBA includes the paragraph mark. If you have tables
> it will also include cell markers.
[quoted text clipped - 35 lines]
> >
> > Thank you in advance for your input on this topic.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.