Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88066

Is there a way to download images from Excel and name it as per data in another cell?

$
0
0

I have an Excel where in Column A there may or may not be images and in Column B there are numbers. I wish to download these images to a folder and name it as per the corresponding entry in Column B.

I have tried the following code but it is downloading the plain white images and naming is done as image 1, image 2 and so on.

Option Explicit
Public Sub ExportAllPics2()
  Dim shp As Shape
  Dim path As String: path = "C:\Images\"
  Dim cnt As Integer: cnt = 1
  Application.DisplayAlerts = False
  With Sheets(1)
    For Each shp In .Shapes
      If shp.Type = msoPicture Then
        shp.Copy
        .Range("A1").Select
        .Paste
        With Selection
          .Height = 600
          .Width = 400
          .Copy
          .Delete
        End With
        With Charts.Add
          .ChartArea.Clear
          .Paste
          .Export Filename:=path & CStr(cnt) & ".png", FilterName:="png"
          .Delete
        End With
        cnt = cnt + 1
      End If
    Next
  End With
  Application.DisplayAlerts = True
End Sub

enter image description here


Viewing all articles
Browse latest Browse all 88066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>