How to count numbers of character in a line

  • Thread starter Doug Robbins - Word MVP
  • Start date
D

Doug Robbins - Word MVP

Hi Thejan,

MsgBox ActiveDocument.Bookmarks("\line").Range.Characters.Count

will display the number of characters (including spaces in the line in which
the selection is located + 1.

The following should be of some help to you:

Dim myrange As Range, i As Integer, j As Integer
j = 1
While j <= ActiveDocument.Paragraphs.Count
Do
If j > ActiveDocument.Paragraphs.Count Then Exit Do
ActiveDocument.Paragraphs(j).Range.Select
Selection.Collapse wdCollapseStart
Set myrange = ActiveDocument.Bookmarks("\line").Range
For i = ActiveDocument.Bookmarks("\line").Range.Words.Count - 1 To 1
Step -1
ActiveDocument.Bookmarks("\line").Range.Words(i).Select
myrange.End = Selection.End
If myrange.Characters.Count < 73 Then
myrange.InsertAfter vbCr
Exit For
End If
Next i
j = j + 1
Loop
Wend

It is not a complete solution for what you want to do however as it will
only deal with there originally being only one paragraph in the document.
It will split that paragraph up into individual paragraphs of no more than
73 characters each.

If the head and the body were in separate sections, each containing only one
paragraph, then you could use

ActiveDocument.Sections(Index).Range.Paragraphs.Count

You might first have to run a macro that does a couple of Edit Replaces to
insert Section Breaks around the head text and the body text so that you
could deal with it section by section.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
T

Thejan Mendis

Hi everybody,

I just thought somebody can help me to create a macro with following
functions.

I have some text document each has two potions

-HEAD-
..
..
..
-BODY-

---------SAMPLE----------

-DATE- 20030601
-ISSU- June 2003
-PAGE- 96
-SECT- jhhkhrthehrkht
-HEAD- Every job i ever had, people always seemed to want to think
small,"**(70 charachter limits)
says Geoffrey Ballard by way of explaining why he went into
-BYLN- fgdfhggdfjg
-TYPE- ***
-SUBJ- efforts to promote vehicles powered by zero-emission hydrogen-***
based fuel cells have earned him such accolades
-NAME- ***


-BODY-

I said this years ago and I see no reason to change my mind: The
family-owned, garaged vehicle is the last vehicle that's going to
get a fuel cell. Fuel cells are still 30 times the cost of what
they need to be for the automotive market. We will need to have
huge experimental fleets, where we will put hundreds of people in
controlled environments and see what they do with these vehicles.
Are people going to be buying them and taking them apart to see ho
they work? What sort of problems are we going to create? I doubt
that I will ever see a hydrogen car for personal consumption in a
showroom. But I am certainly going to struggle to stay alive long
enough to see the fleets change--army vehicles, taxis, trucks and

----------------------SAMPLE END-----------

* in the head part there will text and it should not exceed 70 characters
per line. if its gos to more than 70 characters, macro has to put enter or
para break. but it should not break from the middle of a word.

* in the body part, also same rule but charachter limits is 73.



Please help me some


Thejan
 

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