export pictures from excel file

doriannjeshi

Board Regular
Joined
Apr 5, 2015
Messages
69
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 ?
 

Some videos you may like

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,884
Hi

You cannot embed pictures in cells so I guess you mean that you placed the pictures on top of cells?

If that's the case you just have to save a copy of the file as Web Page and you'll get all the images as separate files in the files subfolder.
 

doriannjeshi

Board Regular
Joined
Apr 5, 2015
Messages
69
thanks for the tip , but the jpegs are being saved not by their names How do I make the jpegs keep their names ?
 

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,884
Hi

You are rigth. You get all the files but you lose the names that they have in the worksheet.

If I also wanted the names then I'd then I'd use another method, with vba

2 options
- use a chart object to export all the pictures, saving each with the name they have in the worksheet, for ex.
or
- get the picture files and parse the xml sources for the names (in the xl->(media,drawing) subfolders)

For the first options there are lots of examples available (also here in mrexcel). If you don't know how to do it and can't find examples post back.
For the second option, you have to look into the xml sources for the workbook, open those files and parse them. If you are not used to it, maybe the first option is easier.

Does this help?
 

doriannjeshi

Board Regular
Joined
Apr 5, 2015
Messages
69

ADVERTISEMENT

I don't have any experience with either option :( How do I use a chart object to export the pictures ?
 

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,884
This is an example. It exports the pictures in worksheet "Sheet1" to a folder using the picture names.

Assumes that the pictures names are valid file names and unique.

Try:

Code:
'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

Hope it works OK, haven't tried it for a while.
 

doriannjeshi

Board Regular
Joined
Apr 5, 2015
Messages
69

ADVERTISEMENT

It exports a white picture not with it's name but with name picture 7.jpg
 

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,884
Well, I tried yesterday with excel 2007 and now with excel 2010. Works with no problems.

Check the initialisation of the destination folder and the input worksheet.
 

doriannjeshi

Board Regular
Joined
Apr 5, 2015
Messages
69
The name not showing , named picture.. and a number The picture is ok but I need the name this is the path I am using Const sPathname = "E:\OneDrive\imazheprove\" name of the page is sheet1
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,127,861
Messages
5,627,314
Members
416,239
Latest member
Counselor85027

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top