How to resize a textbox in Visual Basic for Powerpoint 2010

4.9k Views Asked by At

I would like to know if there's a known way to 'fit' a text box (assuming the text does not wrap) in Visual Basic 2010. This could be somewhat equivalent to just defining a text box and letting the entered text define the width / height, like in PowerPoint's GUI where a newly created textbox simply expands as one types. My code is as follows:

Set tbox1 = slideObject.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, Left:=20, Top:=300, Width:=72, Height:=16)

With tbox1.TextFrame.TextRange
  .Text = "the text in the text box"
  .Font.Bold = True
  .Font.Name = "Calibri"
  .Font.Size = 10
End With

With tbox1.Fill
  .Visible = True
  .ForeColor.RGB = RGB(255, 255, 255)
End With

With tbox1.Line
  .Visible = True
  .ForeColor.RGB = RGB(0, 0, 0)
  .Weight = 2
End With

Thanks for the help!!!

2

There are 2 best solutions below

0
On BEST ANSWER

This will resize the shape, but if you allow wordwrap then you end up with a tall skinny shape with one letter per line...

tbox1.TextFrame.WordWrap = False
tbox1.TextFrame.AutoSize = ppAutoSizeShapeToFitText

Do you need text to wrap?

0
On

First we need to change the textbox property to autofit and then based on top,height dimensions, we can arrange and move thementer image description here