Alex
Alex

Reputation: 535

VBA: Add textbox in PowerPoint and assign it to object variable

I can add a textbox to a slide in PowrPoint, but if I try to assign it to a variable, I get error 13: Type mismatch. What am I doing wrong?

Sub Test()

Dim myPresentation As PowerPoint.Presentation
Dim mySlide As PowerPoint.Slide
Dim shpTxtBox As Shape

Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT) 'this works, I'm just not gonna write out the path of the presentation

Set mySlide = myPresentation.Slides.Add(myPresentation.Slides.Count - 14, 12)

'mySlide.Shapes.AddTextbox Orientation:=msoTextOrientationHorizontal, Left:=5, Top:=10, Width:=900, Height:=60 '<---- works
Set shpTxtBox = mySlide.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, Left:=5, Top:=10, Width:=900, Height:=60) '<-----doesn't work

End Sub

Upvotes: 1

Views: 481

Answers (1)

BigBen
BigBen

Reputation: 50143

You'll get a type mismatch because of your declaration.

Dim shpTxtBox As Shape <- this is an Excel shape, not a Powerpoint one.

To fix:

Dim shpTxtBox as Powerpoint.Shape

Upvotes: 1

Related Questions