Trying to correct strange behavior of text boxes when using Excel data to create Powerpoint

Tristor

New Member
Joined
Nov 12, 2010
Messages
7
Howdy,

I've got a function that creates a textbox on a PowerPoint slide and then adds a string of text that's been passed into it to the slide.

Code:
Public Function copy_text(sheet As String, textString As String, slide As Integer, awidth As Integer, aheight As Integer, atop As Integer, aleft As Integer)
Sheets(sheet).Select
' Reference existing instance of PowerPoint
Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.ViewType = ppViewSlide
PPApp.ActiveWindow.View.GotoSlide (slide)
' Reference active slide
Set PPSlide = PPPres.Slides(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)
'Create textbox and populate it
PPSlide.Shapes.AddTextbox msoTextOrientationHorizontal, aleft, atop, awidth, aheight
With PPSlide.Shapes(PPSlide.Shapes.Count).TextFrame.TextRange
.text = textString
.Font.Size = 40
.Paragraphs.ParagraphFormat.Alignment = ppAlignCenter
End With

' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing

End Function
My problem is that when I programatically create textboxes, the text inside is always going downward, even though it has the Orientation property set to horizontal. As soon as I manually resize the textbox it reflows correctly, but it apparently ignores all my alignment and sizing details.

Below is an anonymized screenshot (click for big) of the behavior I'm talking about. Any ideas on how I can resolve this? It doesn't seem to matter how I set my sizing, only the alignment information in the function is taken into effect, although by checking break-points everything seems to be registering in the VBA.



Thanks.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Code:
With PPSlide.Shapes(PPSlide.Shapes.Count).TextFrame.TextRange
.Text = textString
.Parent.Parent.Width = .Parent.Parent.Width * (40 / .Font.Size) 'Where 40 is the font size that you want
.Font.Size = 40
.Paragraphs.ParagraphFormat.Alignment = ppAlignCenter
End With
 
Upvote 0
Thanks for the response SMC. I tried your modification, and unfortunately I still see the same behavior from PowerPoint. Any other ideas?
 
Upvote 0
I take that back, that appears to have resolved the problem after I made another adjustment to the sizing I was feeding to the function. I misunderstood the properties of the AddTextBox method. The sizes are in points (as in font points) not in pixels.

Thanks so much SMC!
 
Upvote 0

Forum statistics

Threads
1,215,092
Messages
6,123,064
Members
449,090
Latest member
fragment

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