PDA

View Full Version : Solved: Justification of text.



N Prakash
03-26-2005, 12:34 AM
Hi! Friends,

I have some ASCII files and when I convert the same to Word file, it does not get justified untill the hard carriage return is removed in each line.

I want to know is there any easy method to justify the whole file. Alternatively I would like to have a Macro, on selection of a paragraph, it should remove the carraige returns and justify the text.

Can I expect some help please.

Regards,

Prakash.

mdmackillop
03-26-2005, 03:55 AM
Welcome to VBAX

Are there only single para marks in your document, or are there double marks where the genuine paragraphs occur? (ie spaces between paragraphs)

N Prakash
03-27-2005, 09:29 PM
Hi! Friend,

There are spaces between paragraphs. What I want is on selection of paragraph, in Macro it has to count the number of lines selected, remove the hard carriage return marks, insert one space & justify the paragraphs. It should not remove the space after the paragraphs.

mdmackillop
03-28-2005, 02:43 AM
Can you post a zipped sample of your text? Use the Go Advanced button and Manage Attachments.

N Prakash
03-28-2005, 04:38 AM
I am sending a sample file as an attachment. It is an ASCII protected file, I have copied and pasted it to word document. Originally it is Aerial 9 pts. I have to change this to Aerial 12 pts. It will not do the justification, as there is carriage return in each line. What I am doing is, I delete the last character, insert space and Justify. In the Macro code, it should go to the end of each line and insert a space and delete the last character. When I select a paragraph, it shoiuld count number of lines selected.

Hope I am clear

mdmackillop
03-28-2005, 10:34 AM
Try the following; let me know how it goes.
Sub ReplacePara()

Dim CountPara As Long

CountPara = Selection.Paragraphs.Count
MsgBox CountPara & " lines selected"

'Replace double Paras with text value
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p^p"
.Replacement.Text = "ParaBreak"
.Forward = True
End With

'Replace single paras with spaces
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "^p"
.Replacement.Text = " "
.Forward = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

'Replace text value with paramark having space after
Selection.Find.ClearFormatting
With Selection.Find.Replacement.ParagraphFormat
.SpaceAfter = 11
End With
With Selection.Find
.Text = "ParaBreak"
.Replacement.Text = "^p"
.Forward = True
.Format = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

N Prakash
03-30-2005, 03:39 AM
Thank you dear friend It is working. I have made following few changes;

I have disabled the line count message box
I have added one line to the code in the end
"Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify"
In the last line of selection it should not remove the paragraph mark. I want to know what is the code and where to insert.
Now what is happening is, it replaces the para, justifies and the next line of the new paragraph brings to the same para. I have to enter a manual para break.

I once again thank you for the help.

Dear Friend

I have added following two line code in the end. It is working except for the last page;

Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeParagraph

Please tell me whether I am right

mdmackillop
03-30-2005, 05:51 AM
That looks right. You might want to format this paragraph mark to add SpaceAfter to get a visual break.

N Prakash
03-30-2005, 09:00 PM
Thanks for all the help

Prakash

Anne Troy
03-30-2005, 09:33 PM
Hi, again, N.

If this is solved for you, please click on Thread Tools (at the top of the page) and "Mark Solved".

Thanks!