Principle:
- The images inside the Excel document are Shape objects that Traverse ActiveSheet's Shapes collection;
- Sets the corresponding Shape object to the temporary variable;
- Add the ChartObject object to the current sheet and set the area size of the ChartObject object with the width and height of the shape that was taken previously;
- Call the Copy method of the Shape object and copy it to the Clipboard;
- Activates the previously created ChartObject object, using its corresponding Activate method, if you do not do this will prompt the error;
- Paste the previously copied picture into the chart property of the ChartObject object, meaning that a picture is affixed to the inserted ChartObject object;
- Then call the export method in the chart property of the ChartObject object, export the picture to the corresponding directory, and name it.
The example code is as follows:
Dim I as Long
Dim Picrow as Long
Dim SKU as String
Dim S as Shape
Dim C as ChartObject
For i = 1 to ActiveSheet.Shapes.Count
Set s = activesheet.shapes (i)
Picrow = S.topleftcell.row
SKU = ActiveSheet.Cells (Picrow, 12)
IF SKU <> "Then
S.copy
Set C = ActiveSheet.ChartObjects.Add (0, 0, s.width, s.height)
C.activate
C.chart.paste
C.chart.export "D:\jibbitz\" & SKUs & ". jpg"
C.delete
End If
Next I
This determines whether the 12th column of the corresponding row of the image has a value, and if it is the name of the image, export the picture.
VBA Export Excel pictures