dcsimg
Results 1 to 6 of 6

Thread: Align a shape within a different shape using VBA PowerPoint

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2019
    Posts
    30

    Align a shape within a different shape using VBA PowerPoint

    Hello,

    I would like to align ( in this case center)a shape( round cornered rectangle) within sharp cornered rectangle in a slide i.e the center point of both shapes should be equal using VBA without using 'Selection'. Please help me!
    Attached Images Attached Images  

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Align a shape within a different shape using VBA PowerPoint

    Why vba?

    Surely you'd just drag it.. much faster than vba...

    Probably you'd need the two to be aligned and either see if there is a center method (or something similar) or do a load of calculations of heights to get middles, put middle of the smaller as the middle of the larger then move up the height/2 to get the other position.

    Either way... what code do you have

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2019
    Posts
    30

    Re: Align a shape within a different shape using VBA PowerPoint

    To align many such boxes in a process chart of different slides, probably a presentation with more than 100 slides. Yeah, I tried setting same center points for boxes, but I was able to do it only by using 'Selection'method. I would like to align boxes where macro determines misalignment of boxes and sets them. I would like to know if there is some approach to determine these boxes in slide of ppt and run centering functionality on them. My Idea is to use naming and referencing them. Any thoughts on this will be helpful. Thank you for the reply. Could you also see my other postings and share thoughts.Any info is so helpful to start.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,568

    Re: Align a shape within a different shape using VBA PowerPoint

    if you post the code using the selection object, someone may be able to suggest the changes to just work with fully qualified ranges of shapes

    in general it is better to use names with some meaning in the context of the slide,
    BUT for automation purposes if is often useful to use sequenced names, so that iterations of all shapes with some base name can easily be constructed
    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

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jun 2019
    Posts
    30

    Re: Align a shape within a different shape using VBA PowerPoint

    I got something like this, how to align them,I trying to replace this.Instead of using selection, the code should identify boxes in slide and align them

    Sub AlignShapesInsideOuterBoxes()
    Dim i As Integer
    Dim parentShape As Shape
    Dim oShape As Shape

    i = 0
    For Each oShape In ActiveWindow.Selection.ShapeRange ' I want to replace this.Instead of using selection, the code should identify boxes in slide and align them
    i = i + 1
    If i = 1 Then
    ' some error message
    Else
    oShape.Left = parentShape.Left + (parentShape.Width - oShape.Width) / 2
    End If

    Next oShape
    End Sub

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,568

    Re: Align a shape within a different shape using VBA PowerPoint

    what are the names of your shapes, how do they align to each other, or which ones do you want to align to which other ones

    the above code probably should just move all the shapes to the center of their parent, presumably the slide, but shapes can probably be contained within other shapes, and in the code as posted, parentshape is nothing as no object is assign to it, so the code should just fail with error
    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

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width