View Full Version : Textframe2 autowrap & AutoSize
jlingle
01-13-2013, 07:19 AM
I am populating a text box with text from excel in PowerPoint 2010. The code is below. The code compiles and runs fine EXCEPT the text in the text box does not adjust its font size to fit within the box (which is a rectangle shape). Does anyone have an idea why not? This is driving me nuts! :bug:
' Update the current template slide with data from UnNames and the Spreadsheet
' Begin by placing the question text in the slide title
With Application.Presentations(CurrentTMPF).Slides(CurrentTMPS).Shapes("Slide-Title")
.TextFrame2.WordWrap = msoTrue
.TextFrame2.AutoSize = msoAutoSizeTextToFitShape
.TextFrame.TextRange.Text = XLBookL.Sheets(NameOfTab).Range(cCats & CStr(CurrentQST + CatNum + 1)) & ": " & _
XLBookL.Sheets(NameOfTab).Range(cQsTxt & CStr(CurrentQST + CatNum + 1)) ' Enter category + current Qs. Text
End With
John Wilson
01-13-2013, 09:06 AM
When you say the Slide Title is a Rectangle Shape do you really mean that or is it really a Slide Title Placeholder (The ones that say Click to add Title)
If it's the latter then the text resize doesn't work correctly with titles. I don't know why and I dont know a workaround except to use some thing else for your text (Like a rectangle shape!)
jlingle
01-13-2013, 05:15 PM
Hi John. Thanks for responding. Every answer I've read of yours over the last year has been right on the money. This one, however, doesn't seem to have worked. I had actual thought about changing the object and tried with a rectangle from the shapes (after deleting the "title" box of the slide.) Same result--the text doesn't shrink until I actually edit the text on the slide. I even tried something new. First I change the settings on my slide template of the rectangle to "not autofit". I then changed the VBA code to first insert the text and then to execute the formatting commands to autosize and fit the text. I did this because I notice when changing the settings by hand that the text would re-size. The code worked in one way. It reset my "Do not autofit" on the template to "Shrink text on overflow." However, even though the VBA code had changed the setting, the text still did not shrink until I edited the text by hand. Still stuck on trying to get this text to shrink up.
John Wilson
01-14-2013, 01:01 AM
Strange it works here. Are you by any chance trying to make this work in slide show mode? It won't shrink the text in that mode. You would probably need to write your own function that reduced the font size until it fitted the shape.
jlingle
01-14-2013, 04:07 AM
Nope. It's in normal mode. Don't know if it might be something about how the text is imported from Excel. I am going to try a quick edit to the text after I import it to see if that does anything. If not, I'll write a function that reduces the text size when the word length exceeds a certain limit. All very curious. Thanks again. John
John Wilson
01-14-2013, 04:16 AM
You might want to write a function that checks the Boundheight of the text against the height available in the shape.
I adapted your code to not use Excel (for testing) but I don't see why it wouldn't work for you.
Sub getText()
With ActivePresentation.Slides(1).Shapes("Slide-Title")
.TextFrame2.WordWrap = msoTrue
.TextFrame2.AutoSize = msoAutoSizeTextToFitShape
.TextFrame2.TextRange.Text = "mega long string of text goes here instead of the Excel TexT. Make it longer if you want!" 'XLBookL.Sheets(NameOfTab).Range(cCats & CStr(CurrentQST + CatNum + 1)) & ": " & _
XLBookL.Sheets(NameOfTab).Range(cQsTxt & CStr(CurrentQST + CatNum + 1)) ' Enter category + current Qs. Text
Call fitMe(.TextFrame2.TextRange, ActivePresentation.Slides(1).Shapes("Slide-Title"))
End With
End Sub
Function fitMe(otxtR As Variant, oshp As Shape)
While otxtR.BoundHeight > oshp.Height
otxtR.Font.Size = otxtR.Font.Size - 1
Wend
End Function
jlingle
01-14-2013, 05:30 AM
Thanks John. I ran out of time this morning, but will try it when I get a chance.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.