Consulting

Results 1 to 3 of 3

Thread: Move Paragraphs Back Up 1 Line

  1. #1
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location

    Move Paragraphs Back Up 1 Line

    Folks,

    good tuesday,

    I am trying to move my paragraphs up but only if it has a square bracket at the end

    I got started but I cant seem to move it up

    Sub MoveUp()
    
    
     Dim oPar As Paragraph
        Dim oRng As Range
        For Each oPar In ActiveDocument.Range.Paragraphs
        
        
            If InStr(oPar.Range.Characters.Last, "[") > 0 Then
            
                Set oRng = oPar.Range
                oRng.Move wdCharacter, -2
                
                'oRng.Next.Paragraphs
                
                oRng.InsertBefore " " & Left(oPar.Range.Text, Len(oPar.Range.Text) - 1)
                
                 
                
            End If
                
                
        Next
    lbl_Exit:
        Exit Sub
        
    
    End Sub
    and an image for illustartive purposes to see what im trying to do


    text.jpg

    I tried to delete characters from the end but that didnt work

    thank you for your help
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    Sub MoveUp()
    Dim oPar As Paragraph
    Dim oRng As Range
    Dim lngIndex As Long
      For lngIndex = ActiveDocument.Range.Paragraphs.Count To 2 Step -1
        If ActiveDocument.Range.Paragraphs(lngIndex - 1).Range.Characters.Last.Previous = "[" Then
          ActiveDocument.Range.Paragraphs(lngIndex - 1).Range.Characters.Last.Delete
        End If
      Next lngIndex
    lbl_Exit:
      Exit Sub
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    Hello Greg,

    nice to see hope you are well


    Now previously one time I had the same situation but it was a word and I was successful in moving that up
    but the minute I tried to move a character up it just wouldn't budge and I tried everything

    I also tried using some regular expressions well that was a fail.

    There have been some mysterious characters appearing in my word

    - i discovered they were non breaking space which i never knew before any how

    But im very happy becuase that square bracket was unsightly in the worng place
    and i had to manually move my paragraphs and my carpol tunnel was very bad this week

    So thank you

    And good evening

    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


Posting Permissions

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