Line Break Macro Need

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
 
M

Mark Tangard

Basically you need to assign the first 70 characters of the
paragraph, plus one, to a string variable, then check to see
if that extra character (the 71st character) is a space or
paragraph mark, and if it isn't, truncate it by looking
backward for a space, using the InStrRev function (same as
InStr except it searches from the end of the string):

Dim s As String
s = "I said this years ago and I see no reason to [...etc....]"
' --- or more likely something like:
' --- s = sourcedoc.Paragraphs(x).Range.Text

If Len(s) > 70 Then
If Mid$(s, 71, 1) = " " Or Mid$(s, 71, 1) = vbCr Then
s = Mid$(s, 1, 70)
Else
s = Mid$(s, 1, 70)
s = Mid$(s, 1, InStrRev(s, " ") - 1)
End If
End If
 

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