Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    552
    Thanks
    0
    Thanked 1 Time in 1 Post

    vba code for ppt find/replace (excel and ppt xp)

    I tried recording a find/replace in powerpoint but it didn't record any code. I need to search for <?> and delete the lines it appears on in all the slides. I am working from excel and controlling ppt from there. How do i do a find and replace from excel to ppt? thank you

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: vba code for ppt find/replace (excel and ppt xp)

    When learning a new object model, if you don't have a book, I recommend searching in the object browser. Based on the attached, it looks as though the relevant Replace method works on a text range. You probably have to loop through all the TextRange objects in the presentation. I think (vaguely recall) that many shapes are potential text range containers, and that shape objects have a boolean HasTextRange property you can check as you comb through the shapes on each slide. A lot of work, it's sounding like.

  3. #3
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    552
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: vba code for ppt find/replace (excel and ppt xp)

    i tried
    for each sld in pptAppl.ActivePresentation.slides
    for each shp in sld.shapes
    if shp.HasTextFrame then _
    shp.TextFrame.TextRange.Replace FindWhat:=<?>, ReplaceWhat:=""
    next shp
    next sld
    next i


    how do i look in the object browser for how to delete the entire line that the <?> occurs on? i tried delete but couldn't find it. thank you for the help.

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: vba code for ppt find/replace (excel and ppt xp)

    I guess change from the Replace method to the Find method. I think the found text will be highlighted. From there perhaps you can extend a selection to the end of the "paragraph" (see, I think in Word, not PowerPoint) or maybe the bullet is its own object and can be deleted. Not sure.

  5. #5
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: vba code for ppt find/replace (excel and ppt xp)

    <P ID="edit" class=small>(Edited by Gary Frieder on 15-Jul-03 15:50. Amended code - clean up objects)</P>In case you haven't yet come up with a solution, see the code below.
    There may be an easier way, but I couldn't find one - this is much more difficult to do in PowerPoint than it is in Word!

    Gary

    <pre>Public Sub DeleteSpecificParas()
    'Call function:
    DeleteParasWithFindString "<?>"

    End Sub
    '-----------------------
    Public Function DeleteParasWithFindString(ByVal FindString As String)

    'Gary Frieder 2003
    'Purpose: Search presentation for paragraphs which contain
    ' specified text; if found, delete entire paragraph

    Dim sld As Slide
    Dim shp As Shape
    Dim OrigText As TextRange
    Dim FindText As TextRange
    Dim FoundText As TextRange
    Dim n As Long

    For Each sld In ActivePresentation.Slides
    For Each shp In sld.Shapes

    If shp.HasTextFrame Then
    Set OrigText = shp.TextFrame.TextRange
    For n = OrigText.Paragraphs.Count To 1 Step -1
    Set FindText = OrigText.Paragraphs(n)
    Set FoundText = FindText.Find(FindWhat:=FindString)

    If Not FoundText Is Nothing Then
    FindText.Delete
    Set FoundText = Nothing
    End If
    Next 'n
    End If

    Next shp
    Next sld

    Set OrigText = Nothing
    Set FindText = Nothing

    End Function
    </pre>


Posting Permissions

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