Solved

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

Posted on 2014-03-05
3
1,462 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 51

Accepted Solution

by:
Rgonzo1971 earned 500 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 51

Expert Comment

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

Why I don't know

Regards
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
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: …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

728 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