export images using vba

amo

Board Regular
Joined
Apr 14, 2020
Messages
141
Office Version
  1. 2010
Platform
  1. Windows
I tried to export images using vba
but the image that was successfully exported cannot be opened
any idea ?

VBA Code:
Sub example()
Dim y As Integer, i As Integer, x As Integer
Dim DirFile As String

On Error Resume Next


MkDir "C:\image\"

y = Sheet17.Range(Sheet17.Range("E2"), Sheet17.Range("A2").End(xlDown)).Count + 1

For i = 2 To y
    For x = 5 To 12
             With Sheets("download").Shapes.Range(Array("Chart 2"))
                If Sheet17.Cells(i, x).Value <> "" Then
                   .Fill.UserPicture Sheet17.Cells(i, x).Value
                   .Chart.Export "C:\image\" & i - 1 & "-" & x - 4 & ".jpeg"
                  
                End If
             End With
    Next x
Next i

End Sub
 

Attachments

  • Screenshot_27.png
    Screenshot_27.png
    9.2 KB · Views: 8

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I'm guessing there's no image to open. Maybe trial...
Code:
.ChartArea.Fill.UserPicture PictureFile:=Sheet17.Cells(i, x).Value
HTH. Dave
 
Upvote 0
If some work then I would suggest making sure your filepaths in Sheet17.Cells(i, x).Value are correct. Dave
 
Upvote 0

Forum statistics

Threads
1,214,960
Messages
6,122,479
Members
449,088
Latest member
Melvetica

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
Back
Top