Consulting

Results 1 to 3 of 3

Thread: Resizing pictures to Placceholder

  1. #1
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location

    Resizing pictures to Placceholder

    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

    [vba]
    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
    [/vba]

    Help please

    Paul

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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.

    [VBA]sngTop = OPLC.Top
    ActiveWindow.View.GotoSlide osld.SlideIndex
    OPLC.Select
    ActiveWindow.View.Paste
    ActiveWindow.View.Slide.Shapes(ActiveWindow.View.Slide.Shapes.Count).Top = sngTop[/VBA]
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •