I am attempting to take the value in Excel cells and populate PowerPoint text boxes. I don't want to link a PowerPoint table to an Excel spreadsheet because the spreadsheet is constantly changing and values are not always in the same rows or the same order.
So I am writing this VBA code to try and populate the text boxes. I've done a lot of VBA, but never attempted this combination. Below is what I have thus far (more code will be put in for additional text boxes, but need to get one working first). I realize the issue has something to do with the object not being properly handled, but not sure how to correct it.
I'm using Excel and PowerPoint 2007. The bold statement is where I receive the error - 438 object does not support this property or method.
Thanks!
Sub valppt()
Dim PPT As PowerPoint.Application
Dim newslide As PowerPoint.Slide
Dim slideCtr As Integer
Dim tb As PowerPoint.Shape
Set PPT = CreateObject("PowerPoint.Application")
PPT.Visible = True
PPT.Presentations.Open "C:\Documents\createqchart.pptx"
Range("F2").Activate
slideCtr = 1
Set newslide = ActivePresentation.Slides(slideCtr).Duplicate
Set tb = newslide.Shapes("TextBox1")
slideCtr = slideCtr + 1
' Do Until ActiveCell.Value = ""
Do Until slideCtr > 2
If slideCtr = 2 Then
tb.TextFrame2.TextRange.Characters.Text = ActiveCell.Value
End If
ActiveCell.Offset(0, 1).Activate
slideCtr = slideCtr + 1
If slideCtr = 38 Then
Set newslide = PPT.ActivePresentation.Slides(slideCtr).Duplicate
ActiveCell.Offset(1, -25).Activate
End If
Loop
End Sub
UPDATE 5/17
While the replication of the slide works, I am still unable to value the textbox. I haven't been able to come up with the right set statement prior to the statement to have the value assigned to the textbox. Right now I don't even have a set statement in there right now, because I haven't been able to get the proper one. Any assistance is appreciated. Below is the latest code.
Sub shptppt()
'
' shptppt Macro
'
Dim PPT As PowerPoint.Application
Dim pres As PowerPoint.Presentation
Dim newslide As PowerPoint.Slide
Dim slideCtr As Integer
Dim tb As PowerPoint.Shape
Set PPT = CreateObject("PowerPoint.Application")
PPT.Visible = True
Set pres = PPT.Presentations.Open("C:\Documents\createqchart.pptx")
Range("F2").Activate
slideCtr = 1
'Set newslide = ActivePresentation.Slides(slideCtr).Duplicate
' Set tb = newslide.Shapes("TextBox1")
pres.Slides(slideCtr).Copy
pres.Slides.Paste
Set newslide = pres.Slides(pres.Slides.Count)
newslide.MoveTo slideCtr + 1
slideCtr = slideCtr + 1
' Do Until ActiveCell.Value = ""
Do Until slideCtr > 2
If slideCtr = 2 Then
tb.Slides.TextFrame2.TextRange.Characters.Text = ActiveCell.Value
End If
ActiveCell.Offset(0, 1).Activate
slideCtr = slideCtr + 1
If slideCtr = 38 Then
Set newslide = PPT.ActivePresentation.Slides(slideCtr).Duplicate
ActiveCell.Offset(1, -25).Activate
End If
Loop
End Sub