Share via

word: ActiveDocument.Characters.Count not equal to Activedocument.Content.StoryLength

Erich Honecker 0 Reputation points
2023-11-19T21:32:54.56+00:00

I found out, that storylength is more then 50% bigger than characters.count.

Why? Should it not be the same?

(word 2010)

Microsoft 365 and Office | Development | Other
Microsoft 365 and Office | Word | For business | Windows
0 comments No comments

2 answers

Sort by: Most helpful
  1. Charles Kenyon 167.7K Reputation points Volunteer Moderator
    2023-11-19T22:03:50.3866667+00:00

    Yes, you would think so.

    But, characters.count may not pick up characters outside of the main story.

    See https://learn.microsoft.com/en-us/office/vba/api/word.characters.

    For instance, in a document I get the following responses in the Immediate Window:

    ? Activedocument.Content.StoryLength

    2

    ? activedocument.Content.Characters.Count

    1

    ? Selection.characters.count

    44

    None of these means what one might think, except for the last one, the selection. They are all about the same document, which contains more that 50 characters. The only one in the main story is the required paragraph mark. There are characters in a header and in a textbox. The characters in the textbox are selected.

    Would you care to save a sample document where this is not the case on OneDrive or SharePoint and post a link to it here?

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

  2. Erich Honecker 0 Reputation points
    2023-11-20T10:22:10.6133333+00:00

    Sorry, I do not know how to do this sample-document thing.

    I try it this way:

    Sub Makro3()
    

    My problem is, if I do a .find in the range, it sometimes returns start- and endpoint values related to the storylength. It is therefor difficult to handle these results.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.