Find and replace text in PPT

5 pts.
Tags:
Microsoft Excel
PowerPoint
VBA
I have a project to find and replace words in PowerPoint from Excel and then save the PowerPoint. My code is working fine. But when PPT has mp3 then it giving errors. Please see the code and tell me what change I should do.
Sub pptopen()Dim a  AsIntegerFor a =2To4Dim pptApp As PowerPoint.Application
Dim pptPres As PowerPoint.Presentation
Dim pptSlide As PowerPoint.Slide
Dim i AsInteger, strString AsStringSet pptApp = CreateObject("PowerPoint.Application")Set pptPres = pptApp.Presentations.Add(msoTrue)' create a new presentationSet pptPres = pptApp.Presentations.Open("D:BirminghamAL.pptx")Dim oSld As Slide
    Dim oTxtRng As TextRange
    Dim oTmpRng As TextRange
    Dim strWhatReplace AsString, strReplaceText AsString' write find text
    strWhatReplace ="Birmingham"' write change text
    strReplaceText = Cells(a,1).Value

     ' go during each slidesForEach oSld In pptPres.Slides
         ' go during each shapes and textRangesForEach oShp In oSld.Shapes
             ' replace in TextFrameSet oTxtRng = oShp.TextFrame.TextRange
            Set oTmpRng = oTxtRng.Replace( _
            FindWhat:=strWhatReplace, _
            Replacewhat:=strReplaceText, _
            WholeWords:=True)DoWhileNot oTmpRng IsNothingSet oTxtRng = oTxtRng.Characters _
                (oTmpRng.Start + oTmpRng.Length, oTxtRng.Length)Set oTmpRng = oTxtRng.Replace( _
                FindWhat:=strWhatReplace, _
                Replacewhat:=strReplaceText, _
                WholeWords:=True)LoopNext oShp
    Next oSld
    Dim strWhatReplace1 AsString, strReplaceText1 AsString' write find text
    strWhatReplace1 ="AL"' write change text
    strReplaceText1 = Cells(a,2).Value

     ' go during each slidesForEach oSld In pptPres.Slides
         ' go during each shapes and textRangesForEach oShp In oSld.Shapes
             ' replace in TextFrameSet oTxtRng = oShp.TextFrame.TextRange
            Set oTmpRng = oTxtRng.Replace( _
            FindWhat:=strWhatReplace1, _
            Replacewhat:=strReplaceText1, _
            WholeWords:=True)DoWhileNot oTmpRng IsNothingSet oTxtRng = oTxtRng.Characters _
                (oTmpRng.Start + oTmpRng.Length, oTxtRng.Length)Set oTmpRng = oTxtRng.Replace( _
                FindWhat:=strWhatReplace1, _
                Replacewhat:=strReplaceText1, _
                WholeWords:=True)LoopNext oShp
    Next oSld
   pptPres.SaveAs ("D:change"& strReplaceText &"."& strReplaceText1 &".pptx")Next a

EndSub

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    I don't know if others can read the code; but as soon as the page renders in a browser, the code disappears in a mass of formatting instructions. It's immediately unreadable. Apparently the code was copied in from some formatting program rather than as text. So the formatting instructions become rendered as text. -- Tom
    125,585 pointsBadges:
    report
  • ToddN2000
    No, bad code, try cutting and pasting code from a text editor like notepad and we'll see if that's any better.
    15,605 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following