none
In a VSTO PowerPoint add-in is it possible to programmatically resize a TextBox to its minimal needed size? RRS feed

  • Question

  • Often in PowerPoint slides there are text boxes which have larger width than what would be needed to fit the text inside them. One such TextBox can be seen in the following screenshot:

    I would like to develop a PowerPoint add-in which does some calculations based on the size of shapes on a slide, so text boxes should not have unnecessary leftover width like in the above example.

    Is it possible in a VSTO add-in to automatically resize text boxes like this to their minimum width (minimum in the sense that no line gets broken)? (The AutoFit setting msoAutoSizeShapeToFitText only resizes the height of the text box, but not its width.)

    Friday, June 6, 2014 7:25 AM

Answers

  • Actually since then I found an approach that seems doable. The TextRange object provides method called RotatedBounds, that returns the exact rendered position and size of the text contained by the text box.

    So if the width of the shape is significantly larger than the width returned by RotatedBounds, that means that the width of the text box can be decreased. It's not trivial, because the resizing has to be done differently based on the text alignment, but this approach seems to be ok.

    Friday, June 6, 2014 2:16 PM

All replies

  • Hello Mark,

    VSTO doesn't provide anything for the text boxes in PowerPoint. That's why I'd recommend asking non-VSTO related questions in the General Office Development forum instead.

    Friday, June 6, 2014 2:11 PM
  • Actually since then I found an approach that seems doable. The TextRange object provides method called RotatedBounds, that returns the exact rendered position and size of the text contained by the text box.

    So if the width of the shape is significantly larger than the width returned by RotatedBounds, that means that the width of the text box can be decreased. It's not trivial, because the resizing has to be done differently based on the text alignment, but this approach seems to be ok.

    Friday, June 6, 2014 2:16 PM