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

    Find/Replace in PPT

    I'm trying to write a macro in powerpt to find and replace a sequential code in a text box and replace it with a cell from excel. I can't find the vba code to do a find/replace in ppt.

    dim i as integer
    dim findthis as string

    for i = 1 to 10
    findthis = "<<" & i ">>"
    next i

    Can someone tell me the code for find and replacing in ppt? thank you

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

    Re: Find/Replace in PPT

    You should be able to find some useful information by looking for Find in the Object Browser (F2 when you're in the VB Editor) - set Look In to PowerPoint, and then do a Search on "Find".

    What comes up indicates that in PPT, Find is a child of the TextRange object.

    The following example comes from the (PPT 2000) VBA help for the Find Method:

    <hr>Find Method Example

    This example finds every occurrence of "CompanyX" in the active presentation and formats it as bold.

    <pre>For Each sld In Application.ActivePresentation.Slides
    For Each shp In sld.Shapes
    If shp.HasTextFrame Then
    Set txtRng = shp.TextFrame.TextRange
    Set foundText = txtRng.Find(FindWhat:="CompanyX")
    Do While Not (foundText Is Nothing)
    With foundText
    .Font.Bold = True
    Set foundText = _
    txtRng.Find(FindWhat:="CompanyX", _
    After:=.Start + .Length - 1)
    End With
    Loop
    End If
    Next
    Next</pre>

    <hr>

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

    Re: Find/Replace in PPT

    Thanks for the code. I found a way to name my text range in ppt. Now I want to look through my active presentation and find the text range i've named txtRng1. Once I select it I want to search for <<1>> and change it to something contained in a cell in Excel.

    How do i select a text range called txtRng1 in ppt? Thanks for the help.

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

    Re: Find/Replace in PPT

    Hi again,

    It looks like my quick look at the PPT object browser didn't go far enough, in taking in only the Find method - it turns out that the Replace method should get closer to what you need.

    Try something along the lines of:

    txtRng1.Replace FindWhat:="<<1>>, ReplaceWhat:=strXLTxt

    (You can more details from the PPT VBA help for the Replace method.)

    Using this method, there shouldn't be any need to select the TextRange.

    Gary

  5. #5
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Re: Find/Replace in PPT

    Is there a method to reference a graphic in Find/Replace? See this question <A target="_blank" HREF=http://www.wopr.com/cgi-bin/w3t/showflat.pl?Cat=&Board=ppt&Number=42974&page=0&vie w=expanded&sb=5>here</A>
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

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

    Re: Find/Replace in PPT

    Hi Catherine,

    I haven't worked with Find in PPT before so don't know if there are any undocumented tricks for doing this, but the Find method itself requires a TextRange object.

    Based on that, there doesn't seem to be any way to find graphic objects themselves using the Find method. If there is some unique property or identifier about these graphics, then it might be able to get hold of them some other way.

    Gary

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

    Re: Find/Replace in PPT

    This code works great from an excel file that i have open. I run it from ppt.

    Sub find_replace()
    Dim sld As Slide
    Dim shp As Shape
    Dim i As Integer
    Dim txtRng As TextRange
    Dim foundText As TextRange
    Dim replaceText As TextRange
    Dim code As String
    Dim pptApp As PowerPoint.Application
    Dim xlApp As Excel.Application
    Dim xlBook As Object
    Dim xlSheet As Excel.Worksheet
    Dim myArray(1 To 359)
    Dim intCell As Integer
    Dim market As String

    intCell = 0
    i = 0

    Set pptApp = GetObject(, "PowerPoint.Application")

    Set xlApp = GetObject(, "Excel.Application")
    xlApp.Visible = True
    Set xlBook = GetObject(, "Excel.Application")
    xlBook.Windows(1).Visible = True
    xlBook.Worksheets(1).Select

    'ActiveWorkbook.Worksheets("Text").Select

    ' fill array with first row in Excel

    For i = 1 To 359
    code = "<<" & i & ">>"
    myArray(i) = xlBook.Cells(i, 1)

    For Each sld In Application.ActivePresentation.Slides
    For Each shp In sld.Shapes
    If shp.HasTextFrame Then
    Set txtRng = shp.TextFrame.TextRange
    Set foundText = txtRng.Find(FindWhat:=code)
    Set replaceText = txtRng.Replace(FindWhat:=code, ReplaceWhat:=myArray(i))
    End If
    Next shp
    Next sld
    Next i
    'Next intCell



    MsgBox ("FindReplace is Finished")
    market = InputBox("filename = ")
    pptApp.ActivePresentation.SaveAs ("P:market & ".ppt")

    pptApp.ActivePresentation.Close

    End Sub


    This save my ppt file. I don't want to close the excel file that I have open. I want to open, however, a different one and run a macro in it. I then want to close it. Then I want to go to the first excel file (that stayed open) and run a macro in it. I want to keep it open

    Now I want to go to a ppt file and open it. I want to enable macros, yes, and update links, yes. How to i do that in powerpoint. Thank you for the help.

Posting Permissions

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