PDA

View Full Version : Resizing pictures to Placceholder



Paul_Hossler
06-29-2011, 05:11 PM
I think I'm almost there

When pasting in a picture, it does not fill the placeholder, and it centers horizonatally and vertically

I'd like to be able to use a macro to resize and reposition the picture so as to fill the original (i.e. Master's) place holder (subject to aspect ratio) and to position the picture to the top of the placeholder

The part I'm having a lot of problems with is figuring out how to get the Master slide layout for that placeholder on that type of slide

It seems that pasting in the picture re-sizes the placeholder height and width and the originals are lost


Option Explicit

Sub FixPictures()

Dim oPres As Presentation
Dim oSlide As Slide
Dim oPlaceHolder As Shape
Dim i As Long

Set oPres = ActivePresentation
Set oSlide = oPres.Slides(2) ' fixed for testing

For Each oPlaceHolder In oSlide.Shapes
If oPlaceHolder.Type = msoPlaceholder Then

If oPlaceHolder.PlaceholderFormat.ContainedType = msoPicture Then
For i = 1 To oSlide.Master.CustomLayouts.Count
If oSlide.Master.CustomLayouts(i).MatchingName = oSlide.CustomLayout.MatchingName Then

'position picture to top of placeholder
'maintain aspect ration
'make picture width = placeholder width
'if picture height > placeholder height then
' make picture height = placeholder height
' center the picture
'endif

MsgBox oSlide.CustomLayout.MatchingName

Stop

End If
Next

End If
End If
Next
End Sub


Help please

Paul

John Wilson
06-30-2011, 09:02 AM
Hi Paul
Try selecting the relevant placeholder before you paste and then use ActiveWindow.View.Paste

I think this will set the height or width to that of the placeholder (depends on aspect)

Maybe this sort of thing (where osld references the slide with the placeholder and OPLC is a reference to the placeholder.

sngTop = OPLC.Top
ActiveWindow.View.GotoSlide osld.SlideIndex
OPLC.Select
ActiveWindow.View.Paste
ActiveWindow.View.Slide.Shapes(ActiveWindow.View.Slide.Shapes.Count).Top = sngTop

Paul_Hossler
06-30-2011, 02:24 PM
Thanks

I'll try that also, but I was trying to get a VBA 'correction' macro, since a lot of times I need to fix other presentations, or a layout reset might change the size and positioning.

Can I incorporate that idea with VBA into a marco to process all sildes?

Paul