Automating Powerpoint from Word

brenton

New Member
Joined
Aug 24, 2011
Messages
33
I found a lot of resources for a search and replace function to find a word that appears on every slide inside of shapes. I got the code to work when it was in powerpoint, but it wont work in the excel module. Again it replaces a certain word on powerpoint slides with the new word from a range in excel. the line in red is where it continues to stop.

Code:
Sub automateppt()
Dim oPPTApp As PowerPoint.Application
   Dim oPPTFile As PowerPoint.Presentation
   Dim oPPTShape As PowerPoint.Shape
   Dim oPPTSlide As PowerPoint.Slide

   
   
   Set oPPTApp = CreateObject("PowerPoint.Application")
   oPPTApp.Visible = msoTrue
   
  With Sheets("Sheet1").Shapes("Object 1").OLEFormat.Verb(Verb:=xlVerbOpen)
  End With



Dim sFindMe As String
Dim sSwapme As String
sFindMe = "Old Word"
'change this to suit
sSwapme = "New Word"
Call changeme(sFindMe, sSwapme)
End Sub
Sub changeme(sFindMe As String, sSwapme As String)
Dim oPPTSlide As Slide
Dim oshp As Shape
Dim otemp As TextRange
Dim otext As TextRange
Dim Inewstart As Integer

[COLOR="Red"]For Each oPPTSlide In oPPTApp.ActivePresentation.Slides[/COLOR]
For Each oshp In osld.Shapes
If oshp.HasTextFrame Then
If oshp.TextFrame.HasText Then

Set otext = oshp.TextFrame.TextRange
Set otemp = otext.Replace(sFindMe, sSwapme, , msoFalse, msoFalse)
Do While Not otemp Is Nothing
Inewstart = otemp.Start + otemp.Length
Set otemp = otext.Replace(sFindMe, sSwapme, Inewstart, msoFalse, msoFalse)
Loop

End If
End If

Next oshp
Next oPPTSlide
End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Sorry I am automating powerpoint from excel. Anybody have any insight on looping through powerpoint slides and shapes to replace only certain words. I was able to successfully change using the "lines" or "word" method but i think this find and replace is what im really looking for.
 
Upvote 0
I've never tried exporting from Excel to PowerPoint before, but I have gone from CATIA, a CAD system, to PowerPoint. Here is some of my code which hopefully may be able to help you:

Dim oPPT As Object
Set oPPT = CreateObject("PowerPoint.Application")

On Error Resume Next
Set oPPT = GetObject("PowerPoint.Application")
If Err.Number <> 0 Then
Set oPPT = New PowerPoint.Application
End If

Dim oPPTPres As PowerPoint.Presentation
Dim oPPSlides As PowerPoint.Slides
Dim oPPSlide1, oPPSlide2, oPPSlide3 As PowerPoint.Slide

oPPT.WindowState=WindowMaximized

Set oPPTPres=oPPT.Presentations.Add()

'title slide
Set objSlide = oPPTPres.Slides.Add(1, 1)
objSlide.Shapes(1).TextFrame.TextRange.Text = partName
objSlide.Shapes(2).TextFrame.TextRange.Text = "Annotation Data"

For i=1 To numCap

Dim objSlide As PowerPoint.Slide
Set objSlide = oPPTPres.Slides.Add(i+1, 36)
objSlide.HeadersFooters.Footer.Visible = True
objSlide.HeadersFooters.Footer.Text = partName
objSlide.HeadersFooters.DateAndTime.Visible = True
objSlide.HeadersFooters.DateAndTime.UseFormat = True
objSlide.HeadersFooters.DateAndTime.Format = 1
objSlide.HeadersFooters.SlideNumber.Visible = True
 
objSlide.Shapes(1).TextFrame.TextRange.Text = capNamer
Set pic=objSlide.Shapes.AddPicture(strName, False, True, 50, 5, 576, 350)
pic.LockAspectRatio=True

Next 'i
 
oPPT.Visible =True
 
Upvote 0

Forum statistics

Threads
1,225,613
Messages
6,186,003
Members
453,334
Latest member
Prakash Jha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top