H
HiThere
Hello:
The macro below is in a Word 2003 doc and performs search-n-replace inside
of PowerPoint 2003 slides pasted normally (not with Special) into the Word
doc. (Hence, it's not for search-n-replace in PowerPoint files, but for
slides pasted into Word files with no OLE linking.)
The search-n-replace process works fine, except that the macro doesn't save
the changes made when it does "objPPT.ActivePresentation.Save" at the very
end. However, if I comment out the lines closing PowerPoint and just I
close PowerPoint manually instead myself in the GUI, then the changes made
by the macro *are* saved to the slide in the Word doc! (???)
I would post this question to the PowerPoint newsgroup, but I think it's an
issue with Word. Anyone have an idea of how to make the macro save the
changes to the embedded slide? Once I've got the macro 100% functional,
I'll post it back here to the group for others to use.
Thank You!!!
***************************************
Sub ReplaceInSlides()
Dim strFind As String
Dim strReplaceWith As String
Dim strMessage As String
Dim strTitle As String
Dim objPPT As PowerPoint.Application
Dim objSlide As PowerPoint.Slide
Dim objShape As PowerPoint.Shape
Dim objTextRange As PowerPoint.TextRange
Dim objTextRangeFound As PowerPoint.TextRange
strMessage = "Enter the text you wish to find in the slides in this Word
doc."
strTitle = "Find What?"
strFind = InputBox(strMessage, strTitle)
strMessage = "Now enter what you wish to replace that text with."
strTitle = "Replace With What?"
strReplaceWith = InputBox(strMessage, strTitle)
'More code will be added to cycle through all slides in the Word doc,
but
'for now it only modifies the first OLE-shape object in the doc...
ActiveDocument.InlineShapes(1).OLEFormat.DoVerb wdOLEVerbOpen
Set objPPT = New PowerPoint.Application
objPPT.Visible = True
Set objSlide = objPPT.ActivePresentation.Slides(1)
For Each objShape In objSlide.Shapes
Set objTextRange = objShape.TextFrame.TextRange
Set objTextRangeFound = objTextRange.Replace(FindWhat:=strFind, _
Replacewhat:=strReplaceWith, WholeWords:=False)
Do While Not objTextRangeFound Is Nothing
Set objTextRange =
objTextRange.Characters(objTextRangeFound.Start + _
objTextRangeFound.Length, objTextRange.Length)
Set objTextRangeFound = objTextRange.Replace(FindWhat:=strFind,
_
Replacewhat:=strReplaceWith, WholeWords:=False)
Loop
Next objShape
objPPT.ActivePresentation.Save ' <--- THIS ISN'T WORKING ???
objPPT.ActivePresentation.Close
objPPT.Quit
End Sub
FYI: I'm using Word 2003 and PowerPoint 2003 on WinXP+SP2 and all the latest
updates to both Windows and Office 2003.
The macro below is in a Word 2003 doc and performs search-n-replace inside
of PowerPoint 2003 slides pasted normally (not with Special) into the Word
doc. (Hence, it's not for search-n-replace in PowerPoint files, but for
slides pasted into Word files with no OLE linking.)
The search-n-replace process works fine, except that the macro doesn't save
the changes made when it does "objPPT.ActivePresentation.Save" at the very
end. However, if I comment out the lines closing PowerPoint and just I
close PowerPoint manually instead myself in the GUI, then the changes made
by the macro *are* saved to the slide in the Word doc! (???)
I would post this question to the PowerPoint newsgroup, but I think it's an
issue with Word. Anyone have an idea of how to make the macro save the
changes to the embedded slide? Once I've got the macro 100% functional,
I'll post it back here to the group for others to use.
Thank You!!!
***************************************
Sub ReplaceInSlides()
Dim strFind As String
Dim strReplaceWith As String
Dim strMessage As String
Dim strTitle As String
Dim objPPT As PowerPoint.Application
Dim objSlide As PowerPoint.Slide
Dim objShape As PowerPoint.Shape
Dim objTextRange As PowerPoint.TextRange
Dim objTextRangeFound As PowerPoint.TextRange
strMessage = "Enter the text you wish to find in the slides in this Word
doc."
strTitle = "Find What?"
strFind = InputBox(strMessage, strTitle)
strMessage = "Now enter what you wish to replace that text with."
strTitle = "Replace With What?"
strReplaceWith = InputBox(strMessage, strTitle)
'More code will be added to cycle through all slides in the Word doc,
but
'for now it only modifies the first OLE-shape object in the doc...
ActiveDocument.InlineShapes(1).OLEFormat.DoVerb wdOLEVerbOpen
Set objPPT = New PowerPoint.Application
objPPT.Visible = True
Set objSlide = objPPT.ActivePresentation.Slides(1)
For Each objShape In objSlide.Shapes
Set objTextRange = objShape.TextFrame.TextRange
Set objTextRangeFound = objTextRange.Replace(FindWhat:=strFind, _
Replacewhat:=strReplaceWith, WholeWords:=False)
Do While Not objTextRangeFound Is Nothing
Set objTextRange =
objTextRange.Characters(objTextRangeFound.Start + _
objTextRangeFound.Length, objTextRange.Length)
Set objTextRangeFound = objTextRange.Replace(FindWhat:=strFind,
_
Replacewhat:=strReplaceWith, WholeWords:=False)
Loop
Next objShape
objPPT.ActivePresentation.Save ' <--- THIS ISN'T WORKING ???
objPPT.ActivePresentation.Close
objPPT.Quit
End Sub
FYI: I'm using Word 2003 and PowerPoint 2003 on WinXP+SP2 and all the latest
updates to both Windows and Office 2003.