Resizing textframes automatically with vba/vbscript

G

Guest

All,

I'm working on an application that populates a number of text frames with
dynamic text.

It uses code like this:

Set oSlide = oPres.Slides("slidename")
Set oShape = oSlide.Shapes("textarea")
oShape.TextFrame.AutoSize = 1
oShape.TextFrame.TextRange = "Blah, blah, blah"

I'm trying to get the textFrame to resize automatically to fix the text, so
that I can then determine it's size in order to fit other text frames around
it.

However, it appears that the textframe isn't resizing automatically.

If I check the presentation after my script has run, and check the
properties of the text frame, "Auto size" is checked, so I'm not sure what
the problem is.

Many, many thanks in advance for any advice or insight!

Cheers,
Matt Stuehler
 
D

David M. Marcovitz

I don't think that autosize works with text added by VBA. You might have
to calculate the size based on the font and the number of lines.
--David

--
David M. Marcovitz
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.loyola.edu/education/PowerfulPowerPoint/
 
S

Shyam Pillai

Autosize works with VBA too but it depends on how it is used.

Dim oShp As Shape
With ActivePresentation.Slides(1).Shapes
Set oShp = .AddTextbox(msoTextOrientationHorizontal, 0, 0, 1, 1)
End With
With oShp
.TextFrame.WordWrap = False
.TextFrame.AutoSize = ppAutoSizeShapeToFitText
.TextFrame.TextRange.Select
With ActiveWindow.Selection.TextRange
.InsertAfter = "This is so cool we need to set it out again."
End With
End With
 
G

Guest

David, Shyam,

Many thanks for your excellent replies - very helpful!

Shyam, a follow-up question: what determines whether AutoSize works? I.e.,
why does it work in your example, but not mine? Is it that you added the
shape programmatically, whereas mine was created in PPT? Or, is it that you
used .InsertAfter, whereas I used TextFrame.TextRange = "Blah, blah, blah"?
Or, something else altogether?

Thanks again!

Cheers,
Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top