Hi everyone
From part of an Excel VBA codebase, I'm failing to automate alignment of just one shape in a PPT presentation.
This seems to be because Align is for ShapeRange rather than for Shape.
In code below, VBA identifies vPic as the active shape ; that's why the SendToBack command works.
But it fails at Alignment, and I cannot generalize alignment to all shapes in the slide.
Is there a way to align just the active shape ?
Sub test()
Dim aP As PowerPoint.Presentation
Dim vPic As PowerPoint.Shape
Set vPic = aP.Slides(1).Shapes.AddPicture(Filename:="c:\temp\screenshot.png")
vPic.Align msoSendToBack
vPic.msoAlignLefts, False ' ?
vPic.msoAlignBottoms, False ' ?
End Sub
' As I can't seem to align just the new attachment (and not other shapes already in the slide) I am presently forced to hard-code the alignment by the following inaccurate method :
' Set vPic = aP.Slides(1).Shapes.AddPicture(Filename:="c:\temp\screenshot.png", LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, Left:=0, Top:=0, Width:=200, Height:=300)
From part of an Excel VBA codebase, I'm failing to automate alignment of just one shape in a PPT presentation.
This seems to be because Align is for ShapeRange rather than for Shape.
In code below, VBA identifies vPic as the active shape ; that's why the SendToBack command works.
But it fails at Alignment, and I cannot generalize alignment to all shapes in the slide.
Is there a way to align just the active shape ?
Sub test()
Dim aP As PowerPoint.Presentation
Dim vPic As PowerPoint.Shape
Set vPic = aP.Slides(1).Shapes.AddPicture(Filename:="c:\temp\screenshot.png")
vPic.Align msoSendToBack
vPic.msoAlignLefts, False ' ?
vPic.msoAlignBottoms, False ' ?
End Sub
' As I can't seem to align just the new attachment (and not other shapes already in the slide) I am presently forced to hard-code the alignment by the following inaccurate method :
' Set vPic = aP.Slides(1).Shapes.AddPicture(Filename:="c:\temp\screenshot.png", LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, Left:=0, Top:=0, Width:=200, Height:=300)
Last edited: