Solved

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

Posted on 2014-03-05
3
1,380 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 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
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
Comment Utility
This works!  But could you explain how and why?  

Thanks
0
 
LVL 48

Expert Comment

by:Rgonzo1971
Comment Utility
I had the same problem in Excel without VBA

Why I don't know

Regards
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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. …
PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now