Consulting

Results 1 to 9 of 9

Thread: Macro for inserting multiple images

  1. #1

    Macro for inserting multiple images

    Hi

    I'm using Powerpoint 2007 and I want to create a macro that will use the Metro design with a 2 content format. I have hundreds of photos and for each page I want it to import the image on the left hand box. When I do this individually, the image is sized 12.57 cm x 8.38 cm which is fine.

    However, I'd also like the macro to automatically format each image and add a solid white line border to each.

    Finally, for the title on each slide I would like it to automatically insert Screenshot 1, Screenshot 2 etc for each slide.

    I really appreciate your help

    Many thanks

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,922
    Location
    Are the images all in one folder?
    Are they all jpegs?
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    Yes they are all in one folder but they are .png images.

    Thanks

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,922
    Location
    You could try this maybe:

    It assumes you have a presentation open with one blank slide in the Metro design and that slide is two content layout.

    Might need a few tweaks as it's top of head code.

    Obviously change the folder path

    [vba]Sub insertPics()


    Dim strFolder As String ' Full path to folder
    Dim strName As String
    Dim oPres As Presentation
    Dim osld As Slide
    Dim ocust As CustomLayout
    Dim x As Long
    ' Edit this:
    strFolder = "C:\Users\John\Desktop\Pics\" 'note the last \

    Set oPres = ActivePresentation
    Set osld = oPres.Slides(oPres.Slides.Count)
    Set ocust = osld.CustomLayout

    strName = Dir$(strFolder & "*.PNG")
    While strName <> ""
    x = x + 1
    With osld.Shapes.AddPicture(strFolder & strName, msoFalse, msoTrue, -1, -1, -1, -1)
    .Line.Visible = True
    .Line.ForeColor.RGB = vbWhite
    End With
    osld.Shapes.Title.TextFrame.TextRange = "Screenshot " & x
    strName = Dir()
    If strName <> "" Then
    Set osld = oPres.Slides.AddSlide(oPres.Slides.Count + 1, ocust)
    ActiveWindow.View.GotoSlide osld.SlideIndex
    End If
    Wend

    End Sub[/vba]
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  5. #5
    That pretty much works. Many thanks

    Just one thing, when you run the macro, it inserts the image in the top left hand corner of the screen. Is there any way you could fix it, so that the image is lined up on the left hand side, next to the "Click to add text" box on the right hand side.

    When I insert the image manually by clicking the "Insert picture from file" icon, it lines up perfectly. If it could do this, that would be great.

    Many thanks for your help.

  6. #6
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,922
    Location
    Ah 2007 act differently to 2010 (where the code works)

    Try this (make sure "Shapes(3)" is the left hand shape.

    [vba]Sub insertPics()


    Dim strFolder As String ' Full path to folder
    Dim strName As String
    Dim oPres As Presentation
    Dim osld As Slide
    Dim ocust As CustomLayout
    Dim x As Long
    ' Edit this:
    strFolder = "C:\Users\John\Desktop\Pics\" 'note the last \

    Set oPres = ActivePresentation
    Set osld = oPres.Slides(oPres.Slides.Count)
    Set ocust = osld.CustomLayout

    strName = Dir$(strFolder & "*.PNG")
    While strName <> ""
    x = x + 1
    With osld.Shapes.AddPicture(strFolder & strName, msoFalse, msoTrue, -1, -1, -1, -1)
    .Cut
    End With
    With osld.Shapes(3)
    .Select
    End With
    ActiveWindow.View.Paste
    With osld.Shapes(3).Line
    .Visible = True
    .ForeColor.RGB = vbWhite
    End With
    osld.Shapes.Title.TextFrame.TextRange = "Screenshot " & x
    strName = Dir()
    If strName <> "" Then
    Set osld = oPres.Slides.AddSlide(oPres.Slides.Count + 1, ocust)
    ActiveWindow.View.GotoSlide osld.SlideIndex
    End If
    Wend

    End Sub[/vba]
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  7. #7
    Works perfectly!

    Many thanks once again

  8. #8
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,922
    Location
    There you go!

    2010 automatically inserts the picture into the first available suitable placeholder. (To be honest I hate that)

    2007 doesn't do this so you need to cut the picture and force it to paste into the placeholder.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  9. #9
    VBAX Regular
    Joined
    Jun 2013
    Posts
    7
    Location
    i have tried the tutorial ,coo stuff

Posting Permissions

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