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:

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
To align the left sides of all shapes in the slide, try...

Code:
aP.Slides(1).Shapes.Range.Align msoAlignLefts, msoFalse

Hope this helps!
 
Upvote 0
In short, if I have a shape in a slide ("In_Situ") and import another ("New") how can I align just the New shape ?

I'm not interested in aligning both shapes in a slide ; In_Situ is where I'd like it.
 
Upvote 0
Sorry, Domenic : my poor terminology.

I wish to center only the new attachment, horizontally and vertically.
 
Upvote 0
Do you mean center horizontally and vertically with respect to the slide?
 
Upvote 0
Assuming that you're running the code from Excel, and using early binding, as per your original post, try to adopt the following code...

Code:
[COLOR=darkblue]Option[/COLOR] [COLOR=darkblue]Explicit[/COLOR]

[COLOR=darkblue]Sub[/COLOR] test()

    [COLOR=darkblue]Dim[/COLOR] ppApp [COLOR=darkblue]As[/COLOR] PowerPoint.Application
    [COLOR=darkblue]Dim[/COLOR] ppPres [COLOR=darkblue]As[/COLOR] PowerPoint.Presentation
    [COLOR=darkblue]Dim[/COLOR] ppShape [COLOR=darkblue]As[/COLOR] PowerPoint.Shape
    
    [COLOR=darkblue]Set[/COLOR] ppApp = [COLOR=darkblue]New[/COLOR] PowerPoint.Application
    [COLOR=darkblue]Set[/COLOR] ppPres = ppApp.ActivePresentation
    
    [COLOR=darkblue]With[/COLOR] ppPres.Slides(1)
        [COLOR=darkblue]Set[/COLOR] ppShape = .Shapes.AddPicture(Filename:="c:\temp\screenshot.png", LinkToFile:=msoFalse, _
            SaveWithDocument:=msoTrue, Left:=0, Top:=0, Width:=200, Height:=300)
        [COLOR=darkblue]With[/COLOR] .Shapes.Range(ppShape.Name)
            .Align msoAlignCenters, msoTrue
            .Align msoAlignMiddles, msoTrue
        [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
    
    [COLOR=darkblue]Set[/COLOR] ppApp = [COLOR=darkblue]Nothing[/COLOR]
    [COLOR=darkblue]Set[/COLOR] ppPres = [COLOR=darkblue]Nothing[/COLOR]
    [COLOR=darkblue]Set[/COLOR] ppShape = [COLOR=darkblue]Nothing[/COLOR]
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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