2

I have an Excel file that contains a column with images that correspond to distinct unique IDs. Basically, through VBA, I want to loop through each image and save it with its name being the unique ID.

I realize you cannot save an image in Excel itself, so I found this VBA code online (found below) that copies the image into PowerPoint and saves it there, but it is not working for me. I am working with Excel 2016, 64 bit.

Any suggestions?

Sub SaveImages()
    'the location to save all the images
    Const destFolder = "C:\Desktop\Images"

    Dim ws As Worksheet
    Set ws = ThisWorkbook.Worksheets("data")

    Dim ppt As Object, ps As Variant, slide As Variant

    Set ppt = CreateObject("PowerPoint.application")
    Set ps = ppt.presentations.Add
    Set slide = ps.slides.Add(1, 1)

    Dim shp As Shape, shpName
    For Each shp In ws.Shapes
        shpName = destFolder & shp.TopLeftCell.Offset(0, 1) & ".png"
        shp.Copy
        With slide
            .Shapes.Paste
            'This is the point where the code breaks, when I try to save
            .Shapes.SaveAs Filename:=destFolder & shpName
            .Shapes(.Shapes.Count).Delete
        End With
    Next shp

    With ps
        .Saved = True
        .Close
    End With
    ppt.Quit
    Set ppt = Nothing
End Sub
GSerg
  • 76,472
  • 17
  • 159
  • 346
BH57
  • 271
  • 2
  • 7
  • 17
  • Possible duplicate of [Export pictures from excel file into jpg using VBA](http://stackoverflow.com/q/18232987/11683) – GSerg Mar 15 '17 at 22:25
  • 1
    Looks like you use 'desFolder' twice: once in shpName and again when you specify the 'Filename' property in the SaveAs command. Also you should have a backslash at the end of the destFolder string when you define it. – Amorpheuses Mar 16 '17 at 00:20

0 Answers0