Laurengineer
Laurengineer

Reputation: 747

In VBA, how do I sequentially add an image to each slide?

I need to add a sequence of images numbered from 0 - 1400 in steps of 56 (0, 56, 112, etc) to each slide in a presentation and then make the background transparent

So far I have:

Sub InsertImage()

ActiveWindow.Selection.SlideRange.Shapes.AddPicture( _
 FileName:="C:\Folder\Image0.bmp", _
 LinkToFile:=msoFalse, _
 SaveWithDocument:=msoTrue, Left:=25, Top:=90, _
 Width:=265, Height:=398.5).Select

End Sub

Sub MakeTransparent()

  With ActiveWindow.Selection.ShapeRange
     .PictureFormat.TransparentBackground = msoTrue
     .PictureFormat.TransparencyColor = RGB(41, 41, 241)
     .Fill.Visible = msoFalse
  End With

End Sub

Which will do each one individually, but this is no faster than doing them one by one?

Any help is much appreciated!

Thanks,

Lauren

Upvotes: 0

Views: 284

Answers (1)

Steve Rindsberg
Steve Rindsberg

Reputation: 14809

Assuming you want to start at Slide 1 and that you've already got enough slides in the presentation to contain all the images, try something like this (total air-code):

Sub InsertImages()

Dim lImageNumber as Long
Dim lSlideNumber as Long 
Dim oSh as Shape

lSlideNumber = 1  ' Slide counter

For lImageNumber = 0 to 1400 Step 56
   Set oSh = ActivePresentation.Slides(lSlideNumber).Shapes.AddPicture( _
     FileName:="C:\Folder\Image" & cstr(lImageNumber) & ".bmp", _
     LinkToFile:=msoFalse, _
     SaveWithDocument:=msoTrue, Left:=25, Top:=90, _
     Width:=265, Height:=398.5)

     lSlideNumber = lSlideNumber + 1

    With oSh
     .PictureFormat.TransparentBackground = msoTrue
     .PictureFormat.TransparencyColor = RGB(41, 41, 241)
     .Fill.Visible = msoFalse
    End With

Next

End Sub

Upvotes: 2

Related Questions