Results 1 to 7 of 7

Thread: Powerpoint macro - Insert shape on bottom right corner (how would I align it)?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2014
    Posts
    18

    Powerpoint macro - Insert shape on bottom right corner (how would I align it)?

    Hi everyone,

    I've whipped together a code for the purpose of inserting 2 shapes onto a slide. One shape I've inserted no problem into the top left hand corner as having a position of 0,0 is easy to do.

    However, I'm trying to input a 2nd shape in the bottom right-hand corner as well. This is where i am having trouble. Visual basic has no 'shp.align = top' feature or something like these lines. (Please refer to green code for where I need help)

    Would someone be able to help me? (I'm a beginner)

    Thanks!!!

    ----

    Sub test()
    Dim sld As Slide
    Dim pre As Presentation
    Dim shp1 As Shape
    Dim shp2 As Shape


    Set pre = ActivePresentation

    For Each sld In pre.Slides
    Set shp1 = sld.Shapes.AddShape(msoShapeRectangle, 0, 0, 20, 20)
    shp1.Line.Visible = msoFalse
    shp1.Fill.Transparency = 1
    Set shp2 = sld.shapes.addshape(msoShapeRangel, 0,0,20,20)
    shp2.line.visible = msofalse
    shp2.fill.transparency = 1

    Next

    End Sub

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Powerpoint macro - Insert shape on bottom right corner (how would I align it)?

    for right, should be sld.width - 20 (shp2.width)
    similar for top
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2014
    Posts
    18

    Re: Powerpoint macro - Insert shape on bottom right corner (how would I align it)?

    Quote Originally Posted by westconn1 View Post
    for right, should be sld.width - 20 (shp2.width)
    similar for top
    Hmm, apologies for the confusion, but how would I incorporate this into the code. Is it something like below? When I add in the comment in green it goes directly into an error. Also, could you clarify why you are using "-20" in the width statement? What if I've using a widescreen slide template vs a standard one?

    For Each sld In pre.Slides
    Set shp1 = sld.Shapes.AddShape(msoShapeRectangle, 0, 0, 20, 20)
    shp1.Line.Visible = msoFalse
    shp1.Fill.Transparency = 1

    Set shp2 = sld.Shapes.AddShape(msoShapeRectangle, 0, 0, 20, 20)
    shp2.Line.Visible = msoFalse
    shp2.Fill.Transparency = 1
    Set shp2.Width = sld.Width - 20
    Next

  4. #4
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Powerpoint macro - Insert shape on bottom right corner (how would I align it)?

    If you want the shape's right edge to be 20 from the edge of the slide, something more like:

    shp2.left = sld.width - shp2.width - 20

    (assumes you've set the width of shp2 already)

    EDIT: I don't think there is a width property for a slide. Are they all 720 wide?

    EDIT2: In 2013, looks like they're 960 wide, so like:

    Code:
    shp.Left = 960 - shp.Width
    would put it right against the slide's right boundary, and that "- X" would bring it X to the left of the boundary.
    Last edited by vbfbryce; Sep 25th, 2014 at 09:24 AM.

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Powerpoint macro - Insert shape on bottom right corner (how would I align it)?

    how would I incorporate this into the code.
    try like
    Code:
    Set shp2 = sld.Shapes.AddShape(msoShapeRectangle, 960 - 20, sld.hight - 20, 20, 20)
    the parameters for adding a shape are left, top, width, height
    your example shows width and height of both to be 20, left and top would be container (slide) with - shape width, slide height - shape height


    if slides have no height property then put the literal value, of the slides height, in place of sld.height

    bryce may post some more later, as i have never used powerpoint i can not be sure of the properties of objects within the model
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Powerpoint macro - Insert shape on bottom right corner (how would I align it)?

    Quote Originally Posted by vbfbryce View Post
    ....EDIT: I don't think there is a width property for a slide. Are they all 720 wide?

    EDIT2: In 2013, looks like they're 960 wide....
    Bryce, try the Slide.CustomLayout.Width property.

  7. #7
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Powerpoint macro - Insert shape on bottom right corner (how would I align it)?

    Thanks, Tin. Thought it HAD to be there somewhere, but did not get there. Once again, you're the man!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width