Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a macro

Status
Not open for further replies.

LAXMIMA

Programmer
Joined
May 3, 2005
Messages
7
Location
IN
I want to create a macro in which it recognizes all lines with characters 55 or less in a document and replaces its line break by paragraph break. What command shall I use?
 
LAXMIMA,

Why are you counting characters?

Word does line wrapping based on page size & margin settings?

Skip,

[glasses] [red]Be advised:[/red]When Viscounts were guillotined just as they were disclosing where their jewels were hidden, it shows to go that you should...
Never hatchet your Counts before they chicken! [tongue]
 
I do not want to line wrapping. As some lines are of 85 characters. I want to remain that lines as it is and only replace smaller lines's line break by paragraph break. It is required in formatting.
 
WHY is it required in formatting? That sounds like a design issue, and perhaps if you clarified your design we could help.

There is a logic problem:

Some lines are 85 characters...OK. You state you want those to remain as they are.....OK. Then you state you want "only smaller line's line break by paragraph break".

If you have lines of 85 characters, then the only way you can have smaller lines is because of a paragraph mark. There is really no such thing, object, as a line break. Word wraps text when it reaches - as Skip pointed out - the margins. So if you have:

text text text text text text text text text text
text text text text
text text text text text text text text text text

the second line has a paragraph mark. Word will not make a shorter line unless it instructed explicitly to do so.

I suggest you turn on Show/Hide, as it will display the paragraph marks.

Gerry
See my Paintings and Sculpture
 
Actually, there is a line break character. The question really is: "why do you need a paragraph break rather than a line break?"

Is this for visual effect or are you feeding the result to another program that requires a particular format?

Also, are you sure that the 'short' lines really end with a line break?
 
OK, true, but I was trying to avoid that as line break characters are not commonly part of user formatting, as per your question are you "sure" the short lines end with a line break.

Gerry
See my Paintings and Sculpture
 

BTW LAX,

There are, broadly speaking, two kinds of character fonts; proportional and fixed.

Most of the fonts are proportional. The Word program figures out how the characters fit. Depending on the characters, you get a greater or fewer number of characters on a line. That's not your problem.

There are also FIXED pitch fonts, like Courier or OCR A. With these you ALWAYS have the same number of characters per inch/centimeter.

Skip,

[glasses] [red]Be advised:[/red]When Viscounts were guillotined just as they were disclosing where their jewels were hidden, it shows to go that you should...
Never hatchet your Counts before they chicken! [tongue]
 
I am trying to format pages of a document. In this document at the end of all lines there is line break. So what I am trying to do is that replace smaller lines with paragraph break and give it a look of different paragraph. So when ever there are shorter lines if line break is replaced by page break and page will look well formatted. As it will contain of different paragraphs.
 


Paragraphs should not be broken into separate lines. Apply a Style to each paragraph. Then modify the Style in accordance with your desires.

Skip,

[glasses] [red]Be advised:[/red]When Viscounts were guillotined just as they were disclosing where their jewels were hidden, it shows to go that you should...
Never hatchet your Counts before they chicken! [tongue]
 
You are not understanding my problem. I have copied one document from PDF to word. As when copied, at the end of each line there was a paragraph break. So I replaced it with line break. Now instead of cheking whole document to insert paragraph breaks where they are needed, what I am trying to do is to first of all create such a macro in which I can replace the line breaks of all shorter lines by paragrapf break. So that in cheking it with PDF document I have then minimal effort. As naturally shorter lines will represent end of a paragraph. So if you can help me out then I will be very thankfull.
 
Suggest you simply adjust the margins of your word doc so that each line reaches the same length as the PDF doc. As long as the font and font sizes are the same, should look just the same.

Incidentally, if you copied/pasted the text from the PDF into Word, why do you need to check it? It will be exactly the same text.

Cheers,
Dave

Probably the only Test Analyst on Tek-Tips

animadverto vos in Abyssus!

Take a look at Forum1393 & sign up if you'd like
 


Get MS Word Copy/Paste-text to word wrap properly faq68-1449

Skip,

[glasses] [red]Be advised:[/red]When Viscounts were guillotined just as they were disclosing where their jewels were hidden, it shows to go that you should...
Never hatchet your Counts before they chicken! [tongue]
 
Copying PDF into Word will certainly have the right TEXT, but the format will be, as LAXMIMA points out, a paragraph mark at the end of each line as it comes from the PDF.

So, depending on the font attributes of the style - even if it is normal style - the actual format could be different.

LAXMIMA - when stating a situation it is very helpful to fully describe the situation. Here is your original post.
I want to create a macro in which it recognizes all lines with characters 55 or less in a document and replaces its line break by paragraph break.

1. This does not state this was text from a PDF.
2. This does not state that YOU put in those line breaks. The original copy paste puts in paragraph marks, as you point out. YOU are putting in the line breaks. Now you want to change some of those line breaks back into paragraph marks. Or so it seems.

OK, so back to the example.

text text text text text text text (paragraph)
text text text text (paragraph)
text text text text text text text text text (paragraph)
text text text text text text text text text (paragraph)
text text text text text text (paragraph)

This comes from the PDF, and you have changed it to:

text text text text text text text (line)
text text text text (line)
text text text text text text text text text (line)
text text text text text text text text text (line)
text text text text text text (line)

Now you want some logic routine to determine, by character length, whether that line break should be changed back to a paragraph mark. I believe what you really want is a way to recognize that, in the example above, the last three lines represent ONE paragraph. The text goes to the space of the margins, continues, goes to space of the margins, continues, then finishes with the shorter third line.

The first two lines are separate paragraphs.

Am I correct in this?



Gerry
See my Paintings and Sculpture
 
Thanks Gerry! You have understood and judge my problem correctly. Now how can we design a macro so that it runs the way we want ie. it recognizes small lines of character 55 or less and replace the line break by paragraph break. Please suggest any macro that works on the theme.
 
The only way I have been able to understand is to spend MY time trying to figure out what you are doing. It would greatly help YOU if, in further posts, you perform some best practices, Please look at the FAQ for posting in this forum. There has been too much traffic due to you not being clear.

OK, fine, that is over. LAXMIMA, have you actually done very much programming? I do not think you are getting this very well. You are not being clear, you are not grasping a concept that is crucial.

You are STILL asking for a second stage routine to fix your first stage routine. In other words, you are still asking for a RETURN of a line break, that you made, to its original state. To fix the results of your previous code.

This is bad programming. You need to ask yourself - what has to be done in the first place. What are the requirements? What needs to be done in logical steps so it runs the way that fulfills the requirements? Nothing more, but nothing less. Running code that fixes some stuff, but makes other stuff WRONG...is bad code.

Think about what is the logic to make it correct in the first place. Try some code, work it, and when you have some actual code to post, post it and we can see how we can help you get it to work properly.

Write out, on paper, what it is you require.
Write out, on paper, the steps (as far as you know) that need to be done for the requirements to be met.

Try recording macros that do the parts. I am very willing to help. I like to help. However, I am not going to post a solution for you. You are going to have to think it through.

Going to give a direction to think about. remember my example?

text text text text text text text (line)
text text text text (line)
text text text text text text text text text (line)
text text text text text text text text text (line)
text text text text text text (line)

You agreed that the last three lines were ONE paragraph, so the two line breaks should really go completely.

OK< let adjust this a little.

text text text text text text text (line)
text text text text (line)
text text text text text text text text text (line)
text text text text text text text text text (line)
text text text text (line)

You agreed line 2 is one paragraph. 3 to 5 is ONE paragraph.
But wait...notice that line 5 is now the SAME length as paragraph/line 2. Tell me. how are you, using character length, going to be able to say THAT one is a paragraph, THAT one is not and belongs to the previous text lines? Both have the same character count.

Your turn...

Gerry
See my Paintings and Sculpture
 
Dear Gerry, Thanks.I have sorted my problem in a different way. Instead of going for character count I designed a macro for replacing "." & linebreak together with page break. And it gave great results. Only 10% of document remained unformatted which I formatted manually.
Thanks again.
 
......shrug...OK, sure. Obviously you have some requirements for such a thing. I am wondering though about what you are doing if you have a paragraph with more than one sentence in it. Each sentence has a ".". And having a page break... this is poor use of Word. A good Word document does not have ANY manually inserted page breaks.

But then, again, I think you are going about this in an inefficient manner. Having a macro make changes, then another macro fix those changes is poor programming.

However, I am glad something worked out for you.

Good luck.

Gerry
See my Paintings and Sculpture
 

Gerry, you're beginning to "sound" like SkipVought!

BTW, I could not have stated it any better. ;-)

Skip,

[glasses] [red]Be advised:[/red]When Viscounts were guillotined just as they were disclosing where their jewels were hidden, it shows to go that you should...
Never hatchet your Counts before they chicken! [tongue]
 
Excuse me???? Of COURSE you could not have stated it any better. What a thought!

.......wait for it





.....You would have stated it MUCH better.

Yuck yuck.


Not. Sound like you Skip? Oh dear, HELP! I have fallen on my puns, and I can't get up.

Gerry
See my Paintings and Sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top