Aligning an attachment in PPT

SteveBIS

New Member
Joined
Jun 24, 2015
Messages
8
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)
 
Last edited:
That's a good solution, Domenic. I thought of somehow Dim'ming vPic as a ShapeRange but hadn't tested whether it could work. This achieves it in an orthodox way. Many thanks. Steve
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Dim'ming vPic as a ShapeRange would result in a type mismatch error, since Shapes.AddPicture returns a Shape object. Any way, glad I could help.

Cheers!
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top