Results 1 to 7 of 7
  1. #1
    Lounger
    Join Date
    Jan 2001
    Location
    Missouri, USA
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Blank lines between paragraphs (VBA - Word 2000)

    I'm trying to write a macro to insert a blank line between paragraphs, but only paragraphs that are in "normal" style.

    I'm converting a series of documents that were created with "normal" style having 1st line indent, no space between paragraphs to documents with "normal" style = no indenting, blank line between paragraphs. All the other styles will be staying 'as-is.' Changing the style properties is easy, but I can't figure out how to get a blank line in there <img src=/S/sad.gif border=0 alt=sad width=15 height=15>

    <img src=/S/help.gif border=0 alt=help width=23 height=15>

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Blank lines between paragraphs (VBA - Word 2000)

    You want something like

    <pre>Dim myRange As Range
    Set myRange = ActiveDocument.Paragraphs(1).Range
    Do While myRange.End < ActiveDocument.Content.End - 1
    If myRange.ParagraphFormat.Style = "Normal" Then
    myRange.InsertAfter vbCrLf
    myRange.Move unit:=wdParagraph
    End If
    myRange.Move unit:=wdParagraph
    Loop
    </pre>


    StuartR

  3. #3
    Lounger
    Join Date
    Jan 2001
    Location
    Missouri, USA
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Blank lines between paragraphs (VBA - Word 2000)

    Awesome! That works great except that it runs into problems with tables. Says that the "myRange.InsertAfter vbCrLf" is not valid action at end of a row. Can I nest another If...Then statement to skip inserting the vbCrLf for paragraphs with tables in them?

    Thank you --

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Blank lines between paragraphs (VBA - Word 2000)

    My Macros always break because of some condition I never thought to check for, it's not like writing in a "real" language where everything is usually fairly well defined.

    Try adding

    <pre> if myRange.Information(wdWithInTable) Then
    or
    If myRange.Information(wdAtEndOfRowMarker) Then
    </pre>


    Depending on whether you want to skip every paragraph inside a table, or just the one at the end of a row. I haven't tested either of these but you should get the idea.

    StuartR

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Blank lines between paragraphs (VBA - Word 2000)

    Do you actually want *a blank line* after your normal paragraphs, or just the space equivalent of a blank line? 'Cos if it's the latter, you just add the requisite amount of space (eg 12pts in 12pt text) under Format, Style, [stylename], modify, paragraph, Space After - or in code:

    ActiveDocument.Styles("Normal").ParagraphFormat.Sp aceAfter = 12

    HTH
    Beryl M


  6. #6
    Lounger
    Join Date
    Jan 2001
    Location
    Missouri, USA
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Blank lines between paragraphs (VBA - Word 2000)

    That fixed the problem. Thanks for all your help!

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  7. #7
    Lounger
    Join Date
    Jan 2001
    Location
    Missouri, USA
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Blank lines between paragraphs (VBA - Word 2000)

    Yep -- actually have to have the extra hard return between paragraphs. The Word files are eventually going to be imported into another application that doesn't recognize paragraph spacing [img]/forums/images/smilies/sad.gif[/img]

    Thanks tho,

Posting Permissions

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