Solved

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

Posted on 2014-03-05
3
1,434 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
[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 50

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 50

Expert Comment

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

Why I don't know

Regards
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

My experience with Windows 10 over a one year period and suggestions for smooth operation
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

733 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