none
Macro to insert ENTER after end of every line RRS feed

  • Question

  • I need a Macro to insert  ENTER after end of every line (without effecting the orignal space of the paragraph( which is in atleast line spacing format). In short the line will be a single line with enter in the end.

    The reason.

    I am trying to enter double space in the end of the paragrap ( to insert double space between two paragraph ) . With continous characters in the paragraph, the formating of the double space is having effect on the the whole para. Kindly help

    I cannot use LINE BREAK asper the rule set by the project


    ALI




    Friday, December 28, 2012 10:14 AM

Answers

  • So you want a paragraph break after each line? As you can see in your own post, the effect can be rather weird. But here is a macro that you can try:

    Sub BreakLines()
        Application.ScreenUpdating = False
        Selection.HomeKey Unit:=wdStory
        Do
            Selection.EndKey Unit:=wdLine
            If Selection.End >= ActiveDocument.Content.End - 1 Then
                Exit Do
            End If
            If Asc(Selection) <> 13 Then
                Selection.InsertParagraphAfter
            End If
            Selection.MoveDown Unit:=wdLine
        Loop
        Application.ScreenUpdating = True
    End Sub


    Regards, Hans Vogelaar

    Friday, December 28, 2012 7:18 PM
  • There is no really good way to prevent that, so I can only suggest to remove all indents before inserting the line breaks:

    Sub BreakLines()
        Application.ScreenUpdating = False
        With ActiveDocument.Content.Paragraphs
            .FirstLineIndent = 0
            .LeftIndent = 0
        End With
        Selection.HomeKey Unit:=wdStory
        Do
            Selection.EndKey Unit:=wdLine
            If Selection.End >= ActiveDocument.Content.End - 1 Then
                Exit Do
            End If
            If Asc(Selection) <> 13 Then
                Selection.InsertParagraphAfter
            End If
            Selection.MoveDown Unit:=wdLine
        Loop
        Application.ScreenUpdating = True
    End Sub

    If you don't like that, I can't help you.

    Regards, Hans Vogelaar

    Saturday, December 29, 2012 11:23 AM

All replies

  • Hi Ali,

    This should be handled via the paragraph space before and/or after settings, preferably by modifying the Style concerned, and not by inserting empty paragraphs. No macros are required for this.

    Please take some time to learn how to use Word. Also, as I have said before, your posts do not belong in this forum; the issues you keep raising are not Developer issues - they're (very) basic end-user issues.


    Cheers
    Paul Edstein
    [MS MVP - Word]



    • Edited by macropodMVP Friday, December 28, 2012 10:55 AM
    Friday, December 28, 2012 10:54 AM
  • Hi Paul,

    I very well know the paragraph space before and/or after settings , but the project requires to me to do the following :-

    End of each Paragraph line spacing should be double

    If I use the after para setting it will show up...( if the page settings are checked )  .. Hence the request...

    I want a Macro to give me a enter after every end of every line without effecting the Para alignement... Kindly help


    ALI


    • Edited by ALI74 Friday, December 28, 2012 11:08 AM
    Friday, December 28, 2012 11:07 AM
  • The specification you quoted does not require an empty paragraph - it requires that line spacing should be double. I, for one, am not going to provide an unnecessary macro. It is not necessary on two counts:

    1. The specification can be satisfied with paragraph formatting (preferably at the Style level); and
    2. Even if a empty paragraph was required, that could easily be achieved via a simple Find/Replace (which is all a macro would do and which you can record for yourself).

    These forums are not a free coding service and your posts are not Developer-related. Please stop posting beginner user questions in this forum.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, December 28, 2012 11:57 AM
  • First of all you are understanding my query !!!!!!!!!!

    I WANT A MACRO WHICH CAN INSERT A ENTER AFTER THE END OF THE LINE IN A WORD DOCUMENT. that'S it . CAN YOU GET THAT MACRO  !!!!!!!!  IF YOU THINK YOU ARE AN EXPERT.........

    AND PLEASE DONT TELL ME AGAIN WHERE TO LOOK FOR THE SOLN .if you do not want to provide any solution , YOU CAN ALWAYS IGNORE MY REQUEST !!!!!.


    ALI

    Friday, December 28, 2012 2:54 PM
  • Ali,

    What you seem to fail to understand is that folks here are growing weary of feeding you fish.  This is not a place for you to come demanding what you want and make feeble attempts to belittle the abilities of those individuals who have previously helped you.

    I for one know a solution, but I am following your advice not to provide it because I don't want to work for you for free.

    If you are interested in a paid solution, feel free to contact me.  


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm


    • Edited by Greg Maxey Friday, December 28, 2012 4:15 PM
    Friday, December 28, 2012 4:00 PM
  • Dear Mr. Greg,

    Thanks for the offer, But i am not in a position to accept it. Though this is not the right forum but i would like to tell you ,I  am presently jobless ( for the last 1 year ) due to a contagious dieases , I have taken this data editing job which i am presently doing from home to meet my family expenses. The " so many macros " request was to help complete the job on time which was possible through macros only.

    Mr.Hans Vogelaar had been a great help in this forum

    Thanks for your offer.......


    ALI

    Friday, December 28, 2012 6:19 PM
  • Ali,

    Unlike your reply to macropod, your reply above reminds me of a quote attributed to Abraham Lincoln, "A drop of honey catches more flies than a gallon of gal."

    There is nothing wrong with asking so many questions about macros.  The point is that this is not the forum for asking general questions about macros.  This is a forum for Word development.

    Try posting your questions in Microsoft Answers, or VBA Express Help for Word, or Microsoft Office forums.  Ask in a manner and tone that you've shown here, avoid the manner and tone you expressed with macropod, and you may be surprised at the helpfulness that you will find.

    http://answers.microsoft.com/en-us/office/forum/customize?page=1&tab=allhttp://www.vbaexpress.com/forum/forumdisplay.php?f=20http://www.msofficeforums.com/


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm




    • Edited by Greg Maxey Friday, December 28, 2012 6:47 PM
    Friday, December 28, 2012 6:33 PM
  • Greg is correct that other forums are more appropriate for your questions, but macropod' suggestion to use Find/Replace should solve your problem with a minimum of work:

    • Press Ctrl+H to activate the Replace dialog.
    • Enter ^p in the 'Find what' box.
    • Enter ^p^p in the 'Replace with' box.
    • Click 'Replace All'.

    Regards, Hans Vogelaar

    Friday, December 28, 2012 6:41 PM
  • Mr. Greg & Mr Hans .. Thanks for the  guidance .. henceforth I will try to use the forums suggested by you....

    But the soln is not working , i have given a example below :-   i want the paragraph output in the second way...( Enter should be entered in the edn of every line ( inshort , it will work as a seperate line..

    Kindly note : I cannot use the line break option here as it will reflect once the pilcrows are activated.

    Para 1

    In the design of automated machine and control system for process,  programmable logic controllers are often used.  For the controller to carry out its intended task,  a control program is necessary.  The design and development of the control program is of vital importance as it constitutes the means for controlling the target process.  It can be seen that

    Change in Para 1

    In the design of automated machine and control system for process,  programmable logic controllers are often used.  For  the controller to carry out its intended task,  a control program is necessary.  The design and development of the control   program is of vital importance as it constitutes the means for controlling the target process.  It can be seen that


    ALI

    Friday, December 28, 2012 7:04 PM
  • So you want a paragraph break after each line? As you can see in your own post, the effect can be rather weird. But here is a macro that you can try:

    Sub BreakLines()
        Application.ScreenUpdating = False
        Selection.HomeKey Unit:=wdStory
        Do
            Selection.EndKey Unit:=wdLine
            If Selection.End >= ActiveDocument.Content.End - 1 Then
                Exit Do
            End If
            If Asc(Selection) <> 13 Then
                Selection.InsertParagraphAfter
            End If
            Selection.MoveDown Unit:=wdLine
        Loop
        Application.ScreenUpdating = True
    End Sub


    Regards, Hans Vogelaar

    Friday, December 28, 2012 7:18 PM
  • i want the paragraph output in the second way...( Enter should be entered in the edn of every line ( inshort , it will work as a seperate line..

    That is a stupid requirement because, when the document is viewed on a computer attached to a different printer, the user is liable to see a different layout - for example, with "In the design of automated machine and control system for process, programmable logic controllers are often used." all on one line and "For"on another line all on its own. Or they might see lines with gaps at the ends of the lines large enough for another word to fit.

    Furthermore, despite what the specifications you quoted say (End of each Paragraph line spacing should be double), you say you want a paragraph break at the end of every line "without effecting the Para alignement". A paragraph break at the end of every line is not the same as double spacing between paragraphs. If the text is justified, it is not possible to have such line breaks without affecting the format. If the paragraphs are auto-numbered, it is not possible to have such line breaks without affecting the format. If the paragraphs have hanging indents or first-line indents, it is not possible to have such line breaks without affecting the format. Etc.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Saturday, December 29, 2012 12:10 AM
  • HI,

    The Macro is working fine as desired ,But in some para where there is special indent of 0.5 , the whole para shift at  special indent of 0.5" after the macro is run.

    Kindly help in modifying the code.

    Thank you very much


    ALI




    • Edited by ALI74 Saturday, December 29, 2012 10:43 AM
    Saturday, December 29, 2012 10:11 AM
  • There is no really good way to prevent that, so I can only suggest to remove all indents before inserting the line breaks:

    Sub BreakLines()
        Application.ScreenUpdating = False
        With ActiveDocument.Content.Paragraphs
            .FirstLineIndent = 0
            .LeftIndent = 0
        End With
        Selection.HomeKey Unit:=wdStory
        Do
            Selection.EndKey Unit:=wdLine
            If Selection.End >= ActiveDocument.Content.End - 1 Then
                Exit Do
            End If
            If Asc(Selection) <> 13 Then
                Selection.InsertParagraphAfter
            End If
            Selection.MoveDown Unit:=wdLine
        Loop
        Application.ScreenUpdating = True
    End Sub

    If you don't like that, I can't help you.

    Regards, Hans Vogelaar

    Saturday, December 29, 2012 11:23 AM
  • Thanks for all the support . I will use the macro......... will do some manual work.

    A BIG THANKS :)


    ALI

    Saturday, December 29, 2012 12:32 PM
  • Thank you, Hans Vogelaar!

    This has been a great solution for an elderly gentleman I work with. He has difficulty using pen & paper & wants to use his computer to edit Word docs, line by line. I inserted a couple extra breaks, set his text to red & it is so much easier for him! 

    Sunday, December 8, 2013 4:16 PM
  • Dear Hans Vogelaar,

    Hi. Although my answer might seem late relative to your post, I'm actually writing to thank you, not only for the working solution to my problem as stated by the first questioner (which I found through Google search), but also for the refreshingly new style of VBA macro writing I find in your solution, which is deceptively simple, yet elegant, effective and instructive in terms of how to program in VBA in general. For me, it solves a long-standing issue about moving through a document and looping at the same time without running out of steps to move through. Again thanks for this brilliant and beautiful solution.

    Majid.


    Tuesday, August 4, 2015 12:25 PM