doriannjeshi
Board Regular
- Joined
- Apr 5, 2015
- Messages
- 214
- Office Version
- 2019
- Platform
- Windows
Hi, I have an excel file which has several hundreds pictures embeded in cells in .jpg format I want to export them all How can I do it ?
'PGC 201212
' Export pictures from a worksheet to a folder
Sub ExportRangeJPG()
Dim ws As Worksheet
Dim chtO As ChartObject
Dim pic As Picture
Dim lPic As Long
Const sPathname = "c:\tmp\PicTest\"
Set ws = ActiveWorkbook.Worksheets("Sheet1")
Set chtO = ws.ChartObjects.Add(1, 1, 1, 1)
For lPic = 1 To ws.Pictures.Count
Set pic = ActiveSheet.Pictures(lPic)
' resize the chartobject to the dimensions of the picture
With chtO
.Width = pic.Width
.Height = pic.Height
End With
' paste the picture into the chart object
pic.Copy
chtO.Chart.Paste
' export the chart to a file
chtO.Chart.Export sPathname & ws.Pictures(lPic).Name & ".jpg"
Next lPic
' clean up
chtO.Delete
End Sub