Consulting

Results 1 to 6 of 6

Thread: Text fit properly within different size shapes to its maximum size using vba code.

  1. #1

    Text fit properly within different size shapes to its maximum size using vba code.

    Sir, need some help to configure emoji(as a text) to properly fit(cover almost shape size but not overflow) into different size shapes.
    I tried to give some fix font size like 700 & then apply "msoAutoSizeTextToFitShape" but it overflow the shape boundary.
    For better understanding I uploaded sample file where I showed the final outcome.
    Any solution will be highly appreciated.

    Sub proper_fit()
    
    
    Dim shpImage As Shape
    Set shpImage = ActivePresentation.Slides(1).Shapes("shape1")
    With shpImage
        .TextFrame.TextRange.Font.Size = 700
        .TextFrame2.AutoSize = msoAutoSizeTextToFitShape
    End With
    
    
    End Sub
    Attached Files Attached Files

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,137
    Location
    Maybe try this

    Sub proper_fit()
    Dim shpImage As Shape
    Set shpImage = ActivePresentation.Slides(1).Shapes("shape1")
    With shpImage
        .TextFrame2.TextRange.Font.Size = 700
        .TextFrame2.AutoSize = msoAutoSizeTextToFitShape
    End With
    End Sub
    and then try adjusting the font size downwards
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    sir, how to adjust font size with code downwards so that it properly fit for that size shape?

  4. #4
    Find this thread to get idea & its working: Autosize Text in a Shape - one line

    Thanks to @Jhon Wilson sir.

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,095
    Location
    You might want to play with this code too.
    Sub adjust2Fit()
    Dim oshp As Shape
    Set oshp = ActiveWindow.Selection.ShapeRange(1)
    With oshp.TextFrame2
    .TextRange.Font.Size = 100
    .AutoSize = msoAutoSizeShapeToFitText
    .MarginLeft = 0
    .MarginRight = 0
    End With
    oshp.Width = oshp.TextFrame2.TextRange.BoundWidth
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  6. #6
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,137
    Location
    Thank you John.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •