How to set the width as undefined in powerpoint textbox-Collection of common programming errors

I am trying to set the width of a textbox as undefined so it will behave as autofit in powerPoint 2007 I use the following:

shape = slide.Shapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal, left, top, 0f, 0f);

And it look fine on the slide in pp-2007 But when I open the presentation in pp-2010 I get all the characters of the text wraped under each other. This is maybe to be expected when you set the width as 0 but it looks fine in pp-2007. I also use the following but it dose not help:

shape.AutoSize = PpAutoSize.ppAutoSizeShapeToFitText;

I tried it also like this:

shape = slide.Shapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal, left, top, float.NaN, 0f);

But that only gives me a very long textbox

Can anyone help me on this?

  1. You should disable word wrap then PowerPoint will size the text box as required:

    shape.TextFrame.AutoSize = ppAutoSizeShapeToFitText
    shape.TextFrame.WordWrap = msoFalse
    shape.TextFrame.TextRange.Text = "Text"
    

Originally posted 2013-11-09 23:22:08.