Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Jan 2016
    Posts
    77
    Thanks
    18
    Thanked 1 Time in 1 Post

    Insert a White Paragraph Range Block - End of Each Paragraph

    Hi Folks,

    hope all are having a good weekend.

    a bit of an infuriating problem - I thought this was easy to solve but nothings working.

    All I am trying to do is add an empty paragraph white block - at the end of a paragraph to space out the colored text blocks.
    The colored blocks are ranges.


    so something along the lines

    Code:
    oRng.InsertAfter
    
    oRng.Paragraphs.Add.Range.Shading.BackgroundPatternColor = RGB(255, 255, 255)
    Before

    para.png

    After

    pa2.png



    I did try running the macro recorder - applied the code and still couldn't get it to work. I tried all sorts - and just not sure any more

    Why it has to be so difficult for the newbie apprentice

    Any pointers Grateful

    thank you

    PB

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    The separation of white space could be done by inserting an empty paragraph in between each paragraph but there is another way.

    If you set up your styles with a fill AND and thick white paragraph border then you are partly there. The problem with this is that if the paragraph indents and border offsets are EXACTLY the same for each adjoining paragraph then the border will be hidden between those paragraphs. The workaround is therefore to make each style have a slightly different border left and/or right setting. This can be subtle enough that no-one will ever spot the variance because of the size of the white space between the paragraphs and fact you are using pale fills on white.

    See the attached doc for an example where the border left and right setting are slightly different to ensure the border between them stays visible. These styles also have paragraph spacing added to enlarge the spacing beyond the actual white borders.
    BorderForce.docx
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. The Following User Says Thank You to Andrew Lockton For This Useful Post:

    Charles Kenyon (2016-02-06)

  4. #3
    Star Lounger
    Join Date
    Jan 2016
    Posts
    77
    Thanks
    18
    Thanked 1 Time in 1 Post
    Hi Andrew,

    thank you very much for that great tip.

    I never thought of using borders before to preserve those blocks.

    Now the other idea the empty paragraph that would work and to have the paragraph back ground white or automatic.

    You see I have got so many documents to fix - going a bit loopy trying to space them out manually

    I'm fiddling about with below - which only works on one paragraph color - how do I do it for the other color blocks

    Code:
    Dim oPara As Paragraph
    For Each oPara In ActiveDocument.Paragraphs
    
     If oPara.Range.Shading.BackgroundPatternColor = RGB(210, 220, 230) Then
     
        Selection.EndKey Unit:=wdLine                  '  Go to the end of the paragraph
        oPara.Range.Select
        Selection.Paragraphs.Add.Range.Shading.BackgroundPatternColor = RGB(255, 255, 255) 'Add new paragraph with Background Shading white
    
    
    End If
    
              
    Next
    
    End Sub
    I will update on progress

    thank you

    pb
    Last edited by pb89; 2016-02-07 at 11:43.

  5. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    You don't want a blank paragraph after every shaded paragraph, just between two shaded paragraphs. The following macro should do that. Note that the oPara.Next will error on the last paragraph so I added a kludgy error handler to avoid coding this properly.

    Code:
    Sub Addspace()
      Dim oPara As Paragraph
      On Error GoTo ErrEnd
      For Each oPara In ActiveDocument.Paragraphs
        If oPara.Range.Shading.BackgroundPatternColor <> -16777216 And _
                oPara.Next.Range.Shading.BackgroundPatternColor <> -16777216 Then
          oPara.Range.InsertParagraphAfter
          oPara.Next.Range.Style = "Normal"
        End If
      Next
    ErrEnd:
    End Sub
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  6. The Following User Says Thank You to Andrew Lockton For This Useful Post:

    pb89 (2016-02-08)

  7. #5
    Star Lounger
    Join Date
    Jan 2016
    Posts
    77
    Thanks
    18
    Thanked 1 Time in 1 Post

    Smile

    Hello Andrew,

    I knew there had to be some VBA magic ready to be revealed somewhere , the apprentice in training has a lot to learn


    Code:
    If oPara.Range.Shading.BackgroundPatternColor <> -16777216 And _
                oPara.Next.Range.Shading.BackgroundPatternColor <> -16777216 Then
    16million numbers now that's a lot of colors to get my head around.

    I am still getting the hang of

    Code:
    oRng.Paragraphs.Add.Range.Shading.BackgroundPatternColor
    
    AND
    oPara.Range.InsertParagraphAfter
    
    AND
    
    insertAfter


    Now this mighty little script has done the job perfectly - as it said on the TIN.

    I have also learned about the oPara.Next.Range. - that will come handy in my tools collection.

    You see there's so many VBA objects - its subjected me to a lot of grief

    but I am really happy.

    thank you mighty Andrew for Solving this conundrum of the colored ranges paragraph blocks



    Have a great day

    pb

  8. #6
    Star Lounger
    Join Date
    Jan 2016
    Posts
    77
    Thanks
    18
    Thanked 1 Time in 1 Post
    Hello Andrew and all again,

    seeing that you did such a stellar job of chopping the ranges would you or any one else mind lending a hand again.

    Or should I open another thread ?

    I'm simply trying to move these chopped up blocks with their formatting into a 2 Column Table . They will go in Column 2


    Now I've been fiddling about for the past few hours -


    Code:
    Sub MoveToTable()
    
    Dim oPara As Paragraph
    Dim Table as Table
      
    Dim i as long
    
      On Error GoTo ErrEnd
      For Each oPara In ActiveDocument.Paragraphs
        If oPara.Range.Shading.BackgroundPatternColor <> -16777216 
          
    
      ' Copy these blocks into the Table Column 2
    
     ' From the macro Recorder
        Selection.Copy
        Selection.PasteAndFormat (wdFormatOriginalFormatting)
        Selection.Copy
        Selection.PasteAndFormat (wdFormatOriginalFormatting)
    
    
    ' Got confused here -  Am I mean to duplicate the range and copy it into table column
    
    oPara.Range.duplicate
    Selection.Find.Replacement.FormattedText = ActiveDocument.Tables(1).Cell(i, 2).Range.FormattedText
    
    
        End If
      Next
    ErrEnd:
    End Sub
    I have got confused now and at risk of jumbling it all up - all help welcome immensely

    thank you for helping me

    pb

Posting Permissions

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