Consulting

Results 1 to 4 of 4

Thread: Automatically deleting final (empty) paragraph from textboxes

  1. #1
    VBAX Newbie
    Joined
    Nov 2013
    Posts
    2
    Location

    Automatically deleting final (empty) paragraph from textboxes

    Hello,

    i've created a macro in excel that creates slides in PowerPoint using a predefined slide and the data in excel.
    In some of my text boxes, the last (bullet-ed) paragraph only contains a space and i would like to delete this paragraph
    The code below is code i found online and which i adapted (tried to adapt) to suit my needs.


     Sub ClearPara(ActivePresentation As Object)
    ' Replace matching paragraphs with nothing
        Dim sld As Object, shp As Object, intCount As Integer, para As Object, strTarget As String
        strTarget = Chr(32)
        For Each sld In ActivePresentation.Slides
            For Each shp In sld.Shapes
                If shp.HasTextFrame Then
                    If shp.TextFrame.TextRange.Paragraphs.Count > 0 Then
                    ' More than one paragraph; loop backwards
                        For intCount = shp.TextFrame.TextRange.Paragraphs.Count _
                            To 1 Step -1
                            Set para = shp.TextFrame.TextRange.Paragraphs(intCount)
                            If intCount = shp.TextFrame.TextRange.Paragraphs.Count Then
                                ' No trailing CR+LF to match; leaves a blank bullet
                                'MsgBox (para.Text)
                                If para.Text = strTarget Then
                                    para.ParagraphFormat.Bullet.Type = ppBulletNone
                                    para.Delete
                                    
                                End If
                            Else
                                If para.Text = strTarget & Chr(13) & Chr(10) Then
                                    para.Delete
                                End If
                            End If
                        Next
                    End If
                End If
            Next
        Next
    End Sub
    the command
     para.delete
    does remove any text that is present, but it doesn't remove the paragraph brake. Because of this an empty bullet and paragraph brake remain present in the text box.

    Any ideas on how the remove this page break?

    any help is immensely appreciated
    Best regards
    Gert

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Maybe
    Sub ClearPara()
        Dim sld As Object, shp As Object
        Dim otxR   As Object
        Const SPACE As String = " "
        strTarget = Chr(32)
        For Each sld In ActivePresentation.Slides
            For Each shp In sld.Shapes
                If shp.HasTextFrame Then
                    If shp.TextFrame.HasText Then
                        Set otxR = shp.TextFrame.TextRange
                        While otxR.Characters(otxR.Characters.Count) = SPACE _
                        Or otxR.Characters(otxR.Characters.Count) = vbCr
                        otxR.Characters(otxR.Characters.Count).Delete
                        Wend
                    End If
                End If
            Next shp
        Next sld
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Newbie
    Joined
    Nov 2013
    Posts
    2
    Location
    That did exactly what i wanted it to do.
    Thank you so much!

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Yep

    I had this exact problem with an AddIn I wrote for a Multi National Bank so had the code already done!

    It's good when normal people can BENEFIT from the big banks!
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

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