TextFrame.AutoSize not fitting automatically

227 Views Asked by At

I'm using VBA in powerpoint.

I executed following code and AutoSize doesn't work.

A page is created, title and textbox is created into this page. Textbox doesn't fit automatically.

Please help me.

Sub page_create()
    Dim myPresentation As Presentation
    Dim mySlide As Slide
    
    Set myPresentation = ActivePresentation
    'There are 1st slide before!!
    Set mySlide = myPresentation.Slides.Add(2, ppLayoutTitleOnly)
    mySlide.Shapes.Title.TextFrame.TextRange.Text = "Examples"
    Set prevShape = mySlide.Shapes(mySlide.Shapes.Count)
    Set myTextbox = mySlide.Shapes.AddTextbox(msoTextOrientationHorizontal, prevShape.Left, prevShape.Top + prevShape.Height, 0, 0)
    
    myTextbox.TextFrame.AutoSize = ppAutoSizeShapeToFitText
    myTextbox.TextFrame.TextRange.Text = "list, set, int, float, str, tuple"

I changed the order of following sentences, but it doesn't work.

myTextbox.TextFrame.AutoSize = ppAutoSizeShapeToFitText
myTextbox.TextFrame.TextRange.Text = "list, set, int, float, str, tuple"

I referenced this

1

There are 1 best solutions below

0
Oran G. Utan On

adding myTextbox.TextFrame.WordWrap = False worked for me.


Sub page_create()


    Dim myPresentation As Presentation
    Dim mySlide As Slide
    
    Set myPresentation = ActivePresentation
    'There are 1st slide before!!
    Set mySlide = myPresentation.Slides.Add(2, ppLayoutTitleOnly)
    mySlide.Shapes.Title.TextFrame.TextRange.Text = "Examples"
    Set prevShape = mySlide.Shapes(mySlide.Shapes.Count)
    Set myTextbox = mySlide.Shapes.AddTextbox(msoTextOrientationHorizontal, prevShape.Left, prevShape.Top + prevShape.Height, 0, 0)
    
    myTextbox.TextFrame.AutoSize = ppAutoSizeShapeToFitText
    myTextbox.TextFrame.WordWrap = False'here
    myTextbox.TextFrame.TextRange.Text = "list, set, int, float, str, tuple"
    
End Sub