Consulting

Results 1 to 10 of 10

Thread: Solved: Justification of text.

  1. #1

    Angry Solved: Justification of text.

    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.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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)

  3. #3
    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.
    Last edited by N Prakash; 03-28-2005 at 04:05 AM. Reason: spelling mistake

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Can you post a zipped sample of your text? Use the Go Advanced button and Manage Attachments.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    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

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Try the following; let me know how it goes.
    [VBA]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


    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    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

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    That looks right. You might want to format this paragraph mark to add SpaceAfter to get a visual break.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    Thanks for all the help

    Prakash

  10. #10
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Hi, again, N.

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

    Thanks!
    ~Anne Troy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •