VBA Question: Edited slides pasted into Word doc are not saved.

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.
 
H

HiThere

OK, I still haven't found a solution to the problem of the macro not saving
the changes to the slide in Word (the "objPPT.ActivePresentation.Save" line
seems not to actually save), so I'll pay for the solution! :)

The first person to post a solution here will get $5.00 via PayPal from me.
(You'll have to have a PayPal account, of course, to receive it.) A
"solution" will be my source code plus whatever edits are needed to make it
save the change to the embedded slide in Word *and* it has to actually work
on my laptop. This way, you'll get five bucks and everyone else in the
group will get the macro for free.

If nothing else, it'll be fun to see who replies! :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top