PDA

View Full Version : Cannot get picture object to align with horizontal center of slide...why?



ajjava
05-28-2019, 12:37 PM
Here is the scenario, accomplished via VBA:


Picture object pasted to a slide from Excel
Picture object resized to be 90% of original size
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:

24290

John Wilson
05-28-2019, 12:54 PM
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)

24291

ajjava
05-28-2019, 01:04 PM
Not as far as I can tell. Here is a with the object selected. There doesn't appear to be any extra bits.

24292

ajjava
05-28-2019, 01:51 PM
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???

ajjava
05-29-2019, 06:02 AM
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!!

RayKay
07-19-2019, 04:41 AM
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