[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PowerPoint VBA:  Text in shape created with BuildFreeForm does not center as expected

Posted on 2014-03-05
3
Medium Priority
?
1,540 Views
Last Modified: 2014-03-06
Here's another one.  

In PowerPoint 2010 I have a macro that creates a freeform shape using the BuildFreeForm method.  The shape draws fine, but when I try to put text in the shape, it starts above the shape.
Freeform shapeI tried explicitly setting vertical and horizontal anchor, word wrap, etc. but that does not help.
Sub drawhpdialogshape2()

Dim ffb As FreeformBuilder
Dim myshape As Shape
Dim currentslide As Slide

Set currentslide = ActivePresentation.Slides(ActiveWindow.View.Slide.SlideIndex)

Set ffb = currentslide.Shapes.BuildFreeform(msoEditingCorner, 266.8235, 104.3088)
With ffb
    .AddNodes msoSegmentLine, msoEditingAuto, 536.6986, 89.93378
    .AddNodes msoSegmentLine, msoEditingAuto, 521.4486, 288.4338
    .AddNodes msoSegmentLine, msoEditingAuto, 484.1986, 288.4338
    .AddNodes msoSegmentLine, msoEditingAuto, 484.1986, 308.1838
    .AddNodes msoSegmentLine, msoEditingAuto, 454.5735, 288.4338
    .AddNodes msoSegmentLine, msoEditingAuto, 289.5735, 288.4338
    .AddNodes msoSegmentLine, msoEditingAuto, 266.8235, 104.3088
End With

Set myshape = ffb.ConvertToShape
myshape.Fill.ForeColor.ObjectThemeColor = 1
myshape.Line.Visible = msoFalse
With myshape.TextFrame
    .HorizontalAnchor = msoAnchorCenter
    .VerticalAnchor = msoAnchorMiddle
    .MarginLeft = 15
    .MarginLeft = 15
    .AutoSize = ppAutoSizeNone
    .WordWrap = msoTrue
End With

End Sub

Open in new window

If I draw the identical shape by hand using Insert, Shape, freeform, then type text into it, the text is centered nicely in the shape and wraps as you would expect.  

Am I missing something?

Thanks
0
Comment
Question by:Bryce Bassett
  • 2
3 Comments
 
LVL 54

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 39909133
Hi,

By moving one of the points, it should solve the problem
Sub drawhpdialogshape3()

Dim ffb As FreeformBuilder
Dim myshape As Shape
Dim currentslide As Slide

Set currentslide = ActivePresentation.Slides(ActiveWindow.View.Slide.SlideIndex)

Set ffb = currentslide.Shapes.BuildFreeform(msoEditingCorner, 266.8235, 104.3088)
With ffb
    .AddNodes msoSegmentLine, msoEditingAuto, 536.6986, 89.93378
    .AddNodes msoSegmentLine, msoEditingAuto, 521.4486, 288.4338
    .AddNodes msoSegmentLine, msoEditingAuto, 484.1986, 288.4338
    .AddNodes msoSegmentLine, msoEditingAuto, 484.1986, 308.1838
    .AddNodes msoSegmentLine, msoEditingAuto, 454.5735, 288.4338
    .AddNodes msoSegmentLine, msoEditingAuto, 289.5735, 288.4338
    .AddNodes msoSegmentLine, msoEditingAuto, 266.8235, 104.3088
End With

Set myshape = ffb.ConvertToShape
myshape.Fill.ForeColor.ObjectThemeColor = 1
myshape.Line.Visible = msoFalse

With myshape.Nodes
    pointsArray = .Item(1).Points
    currXvalue = pointsArray(1, 1)
    currYvalue = pointsArray(1, 2)
    .SetPosition 1, currXvalue + 1, currYvalue
    .SetPosition 1, currXvalue, currYvalue
End With

With myshape.TextFrame
    .HorizontalAnchor = msoAnchorCenter
    .VerticalAnchor = msoAnchorMiddle
    .MarginLeft = 15
    .MarginLeft = 15
    .AutoSize = ppAutoSizeNone
    .WordWrap = msoTrue
End With

End Sub

Open in new window

Regards
0
 

Author Comment

by:Bryce Bassett
ID: 39909898
This works!  But could you explain how and why?  

Thanks
0
 
LVL 54

Expert Comment

by:Rgonzo1971
ID: 39909993
I had the same problem in Excel without VBA

Why I don't know

Regards
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question