export images using vba

amo

Board Regular
Joined
Apr 14, 2020
Messages
79
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: 5

Some videos you may like

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

NdNoviceHlp

Well-known Member
Joined
Nov 9, 2002
Messages
2,751
I'm guessing there's no image to open. Maybe trial...
Code:
.ChartArea.Fill.UserPicture PictureFile:=Sheet17.Cells(i, x).Value
HTH. Dave
 

amo

Board Regular
Joined
Apr 14, 2020
Messages
79
Office Version
  1. 2010
Platform
  1. Windows
some work and some not work
 

NdNoviceHlp

Well-known Member
Joined
Nov 9, 2002
Messages
2,751
If some work then I would suggest making sure your filepaths in Sheet17.Cells(i, x).Value are correct. Dave
 

Watch MrExcel Video

Forum statistics

Threads
1,126,998
Messages
5,622,097
Members
415,876
Latest member
csibonga2k17

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