Stringlen of section 2

A

Alan Stancliff

Here's a simple question with perhaps not so simple an answer.

Supposing one has a document, and that document is divided into three
continuous section breaks created by Insert>Break>Continuous. Now
suppose I wanted to find out how many ANSI characters are in that
section, including spaces, punctuation, returns, and alphanumeric
characters, divide that sum by 65, and put the resulting floating
integer into a variable. How would I create a macro that would do that.

I hope I'm not trying anyone's patience.

Regards,

Alan Stancliff
 
J

Jay Freedman

Hi Stefan,

Sorry to disagree, but .Words.Count won't return the count of characters.
This will:

x = ActiveDocument.Sections(2).Range.ComputeStatistics( _
wdStatisticCharactersWithSpaces) / 65#

As a minor quibble, declaring x as Double is overkill; a Single is probably
enough precision.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
A

Alan Stancliff

Thanks Stefan and Jay,

I am just now beginning to get into VBA, and I appreciate your advice.

I was playing with the code last night, and I realize I'm not sure how
to put that variable into the clipboard. How would one do that?

Regards,

Alan
 
H

Helmut Weber

Hi everybody,

I wonder, what
ComputeStatistics(wdStatisticCharactersWithSpaces)
is counting.

I got a section containing 9 text characters: "123456789",
like that:

::::::::::::Section Break (continuous)::::::::::::::
123456789¶




::::::::::::Section Break (continuous)::::::::::::::

However:
Sub Test40089()
With ActiveDocument.Sections(2).Range
.Select
MsgBox .ComputeStatistics(wdStatisticCharactersWithSpaces) '8 !!??
MsgBox .ComputeStatistics(wdStatisticCharacters) ' 9
MsgBox .Characters.Count ' 15, yes
MsgBox Len(ActiveDocument.Sections(2).Range) ' 15, yes
End With
End Sub


--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
A

Alan Stancliff

Thanks Jay, for the link.

I think I played with the suggestions in that link, which I found by
searching on keywords in the forum. However, I got some kind of error
message. I thought it might have been either a data mismatch, because x
is a number and not a string, or perhaps I didn't enter or apply the
code correctly.

I'll revisit this issue tonight and see what I can figure out.

Regards,

Alan
 
S

Stefan Blom

Jay: You are right, of course. I really didn't read the original message
very carefully. :-(

Alan: I apologize for any confusion.

--
Stefan Blom
Microsoft Word MVP


in message
 
A

Alan Stancliff

No need to apologize, Stefan,

I appreciate the opportunity to learn that this thread has given me, and
you have helped me in that respect.

Everybody here is so patient with me, and I really am quite grateful.

Regards,

Alan
 
S

Stefan Blom

Alan Stancliff said:
No need to apologize, Stefan,

I appreciate the opportunity to learn that this thread has given me, and
you have helped me in that respect.

Everybody here is so patient with me, and I really am quite grateful.

And I'm grateful that you are patient with *me*. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top