PDA

View Full Version : VBA to export images from cells to a folder with a specific name (MSO 2011 or 2016)



idealmax
11-07-2016, 03:40 AM
Hi everyone,

I'm new to the forum and an average experienced excel user however, I never worked with VBA before and I think I need it to solve this problem.
For my work, I have to export images from an excel sheet to a folder in order to bulk upload them to a webshop. To automatically attach the images to the correct product I have to save them as the product code.

17521

In the above example, I have to export the images into a certain folder from column B and save them as the name (product code) of column F.

After exporting them it should be saved to a folder looking like this:

17522

I'm using MSO 2011 for mac and also have access to MSO 2016 (mac) and MSO 2016 (windows).

I really hope that someone can help me out with this problem because there are 1000+ products waiting for me :think:

snb
11-07-2016, 04:40 AM
We don't like crossposting: http://www.helpmij.nl/forum/showthread.php/903957-Hulp-nodig-met-exporteren-van-afbeeldingen

mancubus
11-07-2016, 06:57 AM
i dont know if a solution is found at crosspost.



Sub vbax_57660_export_images_to_folder()
Dim TempChart As Chart
Dim i As Long

With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With

With ActiveSheet
If .Shapes.Count = 0 Then Exit Sub
For i = 1 To .Shapes.Count
If .Shapes(i).Type = msoPicture Then
Set TempChart = Charts.Add
Set TempChart = TempChart.Location(Where:=xlLocationAsObject, Name:=.Name)

TempChart.ChartArea.Width = .Shapes(i).Width
TempChart.ChartArea.Height = .Shapes(i).Height
TempChart.Parent.Border.LineStyle = 0

.Shapes(i).Copy

TempChart.ChartArea.Select
TempChart.Paste

TempChart.Export Filename:=.Parent.Path & "\" & .Cells(.Shapes(i).TopLeftCell.Row, 4).Value & ".jpg", FilterName:="jpg"

.ChartObjects(.ChartObjects.Count).Delete
End If
Next
End With

End Sub


see also:
http://www.vbaexpress.com/forum/showthread.php?10902-Solved-Help-Need-to-export-image-from-Excel

Kenneth Hobs
11-07-2016, 07:01 AM
Welcome to the forum!

You are not alone in cross-posting. New users will often do that without knowing why some don't "like" it. I don't know what snb's link was about. I usually reference the link at the end to explain cross-posting etiquette which basically asks that you post the links to the other posts in each forum. Of course that policy is not doable in some forums where links can not be posted until after your 5th post. http://www.excelguru.ca/content.php?184

I have helped many people with this type of task. If you still need help, please post back.