Consulting

Results 1 to 5 of 5

Thread: Arrange Images relative to each other

  1. #1
    VBAX Regular
    Joined
    Feb 2012
    Posts
    19
    Location

    Arrange Images relative to each other

    Hey Guys , I have a macro that pastes tables as images in a ppt like this

    [VBA]Dim Sh As Shape
    Dim PP As PowerPoint.Application
    Dim PPpres As PowerPoint.Presentation
    Dim xlapp As Excel.Application
    Dim opslide As PowerPoint.Slide
    Dim shp As String

    If optionbutton1.Value = True Then
    xlapp.Range("a132:e142").Copy
    PPpres.Slides(5).Shapes.PasteSpecial DataType:=ppPasteBitmap, link:=msoFalse

    If optionbutton2.Value = True Then
    xlapp.Range("a145:e152").Copy
    PPpres.Slides(5).Shapes.PasteSpecial DataType:=ppPasteBitmap, link:=msoFalse

    End If

    If optionbutton3.Value = True Then
    xlapp.Range("a154:e163").Copy
    PPpres.Slides(5).Shapes.PasteSpecial DataType:=ppPasteBitmap, link:=msoFalse

    End If

    If optionbutton4.Value = True Then
    xlapp.Range("a165:e172").Copy
    PPpres.Slides(5).Shapes.PasteSpecial DataType:=ppPasteBitmap, link:=msoFalse

    End If

    If Optionbutton5.Value = True Then
    xlapp.Range("a174:e178").Copy
    PPpres.Slides(5).Shapes.PasteSpecial DataType:=ppPasteBitmap, link:=msoFalse

    End If

    If optionbutton6.Value = True Then
    xlapp.Range("a180:e184").Copy
    PPpres.Slides(5).Shapes.PasteSpecial DataType:=ppPasteBitmap, link:=msoFalse
    End If



    End If

    [/VBA]

    so it selects which range based on what optionbutton is selected (really a check box but renamed)

    the problem is it pastes them to the slide right in the center and I would like it to count how many pictures there are and arrange their position based on what it has counted.

    I know I can move the pictures up and down with this code
    [vba]
    Set oppslide = PPpres.Slides(5)
    With oppslide
    .Shapes("picture 2").IncrementTop -125
    .Shapes("picture 3").IncrementTop 50
    .Shapes("picture 4").IncrementTop 150
    End With[/vba]

    but I cant figure out how to make it variable , as if there are only 3 pictures and not 4 it crashes because it cant find a "picture 4"

    clear as mud ?

    any insight or even off the wall ideas on how to do this would be great ?

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    I don't like doing this but it might suffice.
    [VBA]On Error Resume Next[/VBA]

  3. #3
    VBAX Regular
    Joined
    Feb 2012
    Posts
    19
    Location
    Quote Originally Posted by Kenneth Hobs
    I don't like doing this but it might suffice.
    [VBA]On Error Resume Next[/VBA]

    I tried to have it count the pictures on the slide and if the value was X then
    increment XXX
    increment XXX
    increment XXX

    if the value was y then

    increment XXX
    increment XXX


    and so on but my count images did not seem to want to work with my if then , no error thrown just nothing ..

    I will try your solution as a last resort as it still does not solve my spacing problem ... because if there are only 2 images the spacing will be different then 4 so the incremental values will be variable depending on how many check boxes there are

  4. #4
    VBAX Regular
    Joined
    Feb 2012
    Posts
    19
    Location
    I know that "picture 2" is always going to be the top, can anyone think of a way to say "picture 3" increment("picture 2") 100

  5. #5
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Since this is the Excel forum, I would guess that all this happens in Excel. If you will post a simple Excel and PowerPoint file, I am sure that we can come up with a good solution.

    You can probably do something like:
    [VBA]With oppslide
    .Shapes("picture 2").IncrementTop .Shapes("picture 1").Top-125
    End With[/VBA]

Posting Permissions

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