PDA

View Full Version : How do I add a shape object to a Powerpoint macro that resizes itself?



JamJar
02-07-2008, 05:41 PM
This is the code that I've been working with so far:
--------------
Sub AddTextBox()

Dim MyText

MyText = InputBox("Enter text here")

For i = 1 To ActivePresentation.Slides.Count
With ActivePresentation.Slides(i).Shapes.AddS... _
0, 0, 720, 30).TextFrame
.TextRange.Text = MyText
End With
Next


End Sub
--------------
I've been reading about the AutoSize method but can't seem to get it to work with my code. All I want to do is create a shape that reshapes itself to fit the text. Any help would be very, very much appreciated!

Paul_Hossler
02-07-2008, 08:32 PM
Maybe ...



Sub AddTextBox()
Dim oSlide As Slide
Dim oShape As Shape
Dim MyText As String
Dim nWidth As Single
MyText = InputBox("Enter text here")
If Len(MyText) = 0 Then Exit Sub
nWidth = ActivePresentation.SlideMaster.Width
For Each oSlide In ActivePresentation.Slides
With oSlide.Shapes.AddTextBox(msoTextOrientationHorizontal, 0, 0, nWidth, 30)
.TextFrame.TextRange.Text = MyText
.TextFrame.AutoSize = ppAutoSizeShapeToFitText
End With
Next
End Sub


Also, it's easier to read if you use the VBA tag insert box

Paul

John Wilson
02-08-2008, 10:33 AM
Or maybe

Sub AddTextBox()
Dim MyText
Dim oTxtbox As Shape
Dim osld As Slide
MyText = InputBox("Enter text here")
For Each osld In ActivePresentation.Slides
Set oTxtbox = osld.Shapes.AddTextBox(msoTextOrientationHorizontal, 10, 10, 20, 20)
With oTxtbox
.TextFrame.WordWrap = False
.LockAspectRatio = False
.TextFrame.TextRange = MyText
.TextFrame.AutoSize = ppAutoSizeShapeToFitText
End With
Next osld
End Sub