VBA Export Excel pictures

Source: Internet
Author: User



Principle:

    1. The images inside the Excel document are Shape objects that Traverse ActiveSheet's Shapes collection;
    2. Sets the corresponding Shape object to the temporary variable;
    3. 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;
    4. Call the Copy method of the Shape object and copy it to the Clipboard;
    5. Activates the previously created ChartObject object, using its corresponding Activate method, if you do not do this will prompt the error;
    6. Paste the previously copied picture into the chart property of the ChartObject object, meaning that a picture is affixed to the inserted ChartObject object;
    7. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.