Transferring macros from Word to Powerpoint

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I created a macro to automate word replacement in Word and cannot copy this
to Powerpoint. Usually, I would create a dummy macro in ppt, then fiddle with
the code to fine-tune. However, 'Create new macro' followed by Ctrl H (find
and replace), or by Alt E, E is not even recorded, all I get is the following:
Sub Macro3()
'
' Macro recorded 18/07/2006 by Simon
'

End Sub
Any pointers helpful
 
The object model for PowerPoint is very different from Word. Text in
PowerPoint resides in shapes on slides, so you will need to cycle thru each
shape on each slide. But why re-invent the wheel...

====Code Start====
Sub ReplaceMyText()

Dim oSld As Slide
Dim oShp As Shape

'Set the words to be used. These can be changed.
Const OrigWord = "Pepperoni"
Const NewWord = "Pineapple & Ham"

'Double check to ensure the loop will not _
create an endless loop
If InStr(1, NewWord, OrigWord) > 0 Then
MsgBox "Replacement can not " & _
"contain original."
Exit Sub
End If

'Look at each slide
For Each oSld In ActivePresentation.Slides

'Look at each shape
For Each oShp In oSld.Shapes

'Check if the shape has any text
If oShp.HasTextFrame = msoTrue Then

'Set up a loop to check for repeated _
words in the text
Do While InStr(1, oShp.TextFrame _
.TextRange.Text, OrigWord) > 0

'Replace the word(s)
oShp.TextFrame.TextRange.Replace _
OrigWord, NewWord

Loop
Next oShp
Next oSld

End Sub
====Code End====

--
Bill Dilworth
A proud member of the Microsoft PPT MVP Team
Users helping fellow users.
http://billdilworth.mvps.org
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
vestprog2@ Please read the PowerPoint FAQ pages.
yahoo. They answer most of our questions.
com www.pptfaq.com
..
 
Doh! Forgot to include the 'end if' statement between the 'loop' and the
'next oShp' commands

Loop
End If
Next oShp


--
Bill Dilworth
A proud member of the Microsoft PPT MVP Team
Users helping fellow users.
http://billdilworth.mvps.org
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
vestprog2@ Please read the PowerPoint FAQ pages.
yahoo. They answer most of our questions.
com www.pptfaq.com
..
 
Hi Bill,
Thanks, as you say, very different... Will need more looking at when less
rushed. For the mo, get 'Compile error: next without for' (Next oShp)...
FatSimon
 
Back
Top