Solved

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

Posted on 2014-03-05
3
1,415 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:versatilebb
  • 2
3 Comments
 
LVL 49

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:versatilebb
ID: 39909898
This works!  But could you explain how and why?  

Thanks
0
 
LVL 49

Expert Comment

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

Why I don't know

Regards
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Setting the Scene Animations in PowerPoint are a great tool to convey messages when used carefuly with the content of your slides. There are plenty of animation effects and options, including a Repeat feature for individual animation effects. …
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
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: …

825 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