Reputation: 237
I want to create a text box in Power Point via VBA excel, this is my code :
Set Sh = PptDoc.Shapes.AddLabel(Orientation:=msoTextOrientationHorizontal, _
Left:=100, Top:=100, Width:=150, Height:=60)
Sh.TextFrame.TextRange.Text = Worksheets("Source").Range("D14")
Sh.TextFrame.TextRange.Font.Color = RGB(255, 100, 255)
But when I am running, it say there is a problem with Activ X ?
Upvotes: 1
Views: 2644
Reputation: 2777
Your code is working properly if Pptdoc
is already defined as PowerPoint slide like the example below
Dim pp As PowerPoint.Application, pptdoc As Slide, pptLayout As CustomLayout
Set pp = CreateObject("PowerPoint.Application")
pp.Visible = True
'If you are creating a new Presentation and New slide the
pp.Presentations.Add
Set pptLayout = pp.ActivePresentation.Designs(1).SlideMaster.CustomLayouts(1)
Set pptdoc = pp.ActivePresentation.Slides.AddSlide(1, pptLayout)
'If you are using an existing presentation then delete above 3 lines use the 2 lines below
'pp.Presentations.Open ("C:\users\User\desktop\test.pptm")
'Set pptdoc = pp.ActivePresentation.Slides(1)
Set Sh = pptdoc.Shapes.AddLabel(Orientation:=msoTextOrientationHorizontal, _
Left:=100, Top:=100, Width:=150, Height:=60)
Sh.TextFrame.TextRange.Text = Worksheets("Source").Range("D14").Value
Sh.TextFrame.TextRange.Font.Color = RGB(255, 100, 255)
Also always try add Microsoft PowerPoint Object library in the tools-references while working with PowerPoint. It is always safe to use .Value
with excel ranges when you intent to write values only.
Upvotes: 2