Consulting

Results 1 to 6 of 6

Thread: Cannot get picture object to align with horizontal center of slide...why?

  1. #1
    VBAX Regular
    Joined
    Mar 2019
    Posts
    73
    Location

    Cannot get picture object to align with horizontal center of slide...why?

    Here is the scenario, accomplished via VBA:

    1. Picture object pasted to a slide from Excel
    2. Picture object resized to be 90% of original size
    3. Now I'd like to horizontally center the object on the slide
      • No matter what I try, the picture object ends up cocked to the left, rather than being centered with the slide.
      • The most current attempt is using .Align msoAlignCenters, msoTrue
      • The object is NOT centered on the slide
      • I also tried variations of .width/2, .height/2...and the object ended up halfway off the slide


    Here is the snippet of the most current attempt:
    osld.Shapes("Picture 2").Select               
    With ActiveWindow.Selection.ShapeRange
                    
                    .ScaleHeight 0.9, msoTrue
                    .ScaleWidth 0.9, msoTrue
                    'set to msoTrue to align to slide
                    'set to msoFalse to align to shapes
                    .Align msoAlignCenters, msoTrue
                     '.Align msoAlignMiddles, msoTrue
                    End With

    And what it returns:

    error on copy paste CPAT7.JPG

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    The code looks fine. Are you sure the image does not have a white / transparent area to the right of the visible area? Here's what I gotr with your code on a standard picture (I commented Middles back in)

    centered.jpg
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Regular
    Joined
    Mar 2019
    Posts
    73
    Location
    Not as far as I can tell. Here is a with the object selected. There doesn't appear to be any extra bits.

    error on copy paste CPAT8.JPG

  4. #4
    VBAX Regular
    Joined
    Mar 2019
    Posts
    73
    Location
    NEVER MIND...I SEE WHY THAT HAPPENED (below).




    Here's an interesting development: If I step through the code via F8, the object centers perfectly. If I just run it, it is off-center. What the heck???

  5. #5
    VBAX Regular
    Joined
    Mar 2019
    Posts
    73
    Location
    Just to be clear, the "never mind" only applied to the comment prior to this one, about the stepping-through. I'd still love to know why the macro won't center the picture object. I did try a version of the code where each slide is specifically selected, in which case the code DOES work, but I know it's bad practice to physically select objects, rather than just referring to them. Thanks!!

  6. #6
    VBAX Contributor
    Joined
    Dec 2018
    Location
    South London
    Posts
    115
    Location
    Hi Ajjava

    I don't know if this is useful, but you might be able to salvage some code from this VBA.
    Currently it stands that, if you click an image (or more) then run this tool, it centers content on the slide.

    Sub CenterOnSlide()
     
    On Error GoTo err
    With ActiveWindow.Selection.ShapeRange
    'set to msoTrue to align to slide
    'set to msoFalse to align to shapes
    .Align msoAlignCenters, msoTrue
    .Align msoAlignMiddles, msoTrue
    End With
    Exit Sub 
    err: 'error
    MsgBox "Please select one or more shapes!"
    End Sub

Posting Permissions

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