How use vba to center vertically and horizontally ALL images ?

M

MoiMeme

Hi,

big slideshow, with automatically imported images.

Now I want to

- center all of them in the page, horizontally and vertically
- resize them all to same height, keeping height-widt ratio

Are these procedures achievable via vba so i do not have to manually do it
200 times ?

TIA to all experts here !
 
B

Bill Dilworth

Hi MoiMeme,

Try this (as long as the pictures are actually pictures and not filled
autoshapes)...
'-----------------------------
Sub DeAwry()

Dim osld As Slide
Dim oshp As Shape
Dim x As Integer
Dim y As Integer

With ActivePresentation.PageSetup
x = .SlideWidth / 2
y = .SlideHeight / 2
End With

For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes

If oshp.Type = msoPicture Then
oshp.Left = x - (oshp.Width / 2)
oshp.Top = y - (oshp.Height / 2)
End If

Next
Next

End Sub
'-----------------------------
 
J

John Wilson

Bill's code will work just fine. Here's an alternative approach. If they are
real pictures use the code as posted if its a 2003 album use the alternative


'Copy from here -----------------
Sub centrepicand size()
Dim i As Integer
Dim osld As Slide
Dim opic As ShapeRange
For Each osld In ActivePresentation.Slides
For i = 1 To osld.Shapes.Count
If osld.Shapes(i).Type = msoPicture Then
'if filled shapes (2003 album) use this instead
'if osld.shapes(i).fill.type=msoFillPicture then
Set opic = osld.Shapes.Range(i)
opic.LockAspectRatio = True
opic.Height = 200'change to suit
opic.Align msoAlignMiddles, msoTrue
opic.Align msoAlignCenters, msoTrue
End If
Next i
Next osld
End Sub
To here -----------------------
--

john ATSIGN PPTAlchemy.co.uk
Custom vba coding and PPT Makeovers
Free PPT Hints, Tips and Tutorials
http://www.pptalchemy.co.uk/powerpoint_hints_and_tips_tutorials.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top