Problem populating PowerPoint textbox with value from Excel VBA code

Drewzer

New Member
Joined
May 17, 2013
Messages
1
Hi, I am using Excel and PowerPoint 2007 and have written VBA code in Excel to populate a textbox (TextBox1) on a PowerPoint slide.

For a number of reasons I don't want to create a link between the PPT textbox and an Excel cell. I just want to take the value in the Excel cell and place it into the PPT textbox.

The first thing I do is open the PPT file and duplicate the first slide. The duplicate method was replicating the slide, but was causing other issues, so I got some coding tips to change they way I copy the main slide. Below is the code I have written, which will not compile for the moment.

Any advice would be helpful. Please let me know if you need additional info and thanks!

Sub createppt()
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
 
Welcome to the forum.

I would be happy to try and help but I don't understand where you are having a problem.

What problems did you have using duplicate? Until newslide is set to something there isn't a way to set the field.

It looks like 1 problem is that you are setting the value for tb before newslide is defined so tb is nil. You need to reset the tb object every time you change newslide.
 
Upvote 0

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