Save Workbook Chart as Images

smitpau

Board Regular
Joined
Apr 2, 2020
Messages
167
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'd like to be able to save all the workbook charts as images.

The folder structure would ideally be like this:

C:\Users\Pictures\Workbook Name\Sheet Name\Chart Title Name

Some code is below which I've started on but am a bit stuck.

Any help would be appreciated thanks.

VBA Code:
Sub ExportSheetCharts()

'Create a variable to hold the path and name of image
Dim CurrentSheet As Worksheet
Dim cht As ChartObject
Dim strUserName As String
Dim subfolder As String
Dim strFileFullName As String


strUserName = Application.UserName
subfolder = ActiveSheet.Name
strFileFullName = ThisWorkbook.FullName
 
If Len(Dir("C:\Users\" & strUserName & "\Pictures\" & strFileFullName & "\")) = 0 Then
 MkDir ("C:\Users\" & strUserName & "\Pictures\" & strFileFullName & "\")
End If


'Export the chart
           For Each sht In ActiveWorkbook.Worksheets
           For Each cht In ActiveSheet.ChartObjects
           cht.Chart.Export "C:\Users\" & strUserName & "\Pictures\" & strFileFullName & "\" & subfolder & cht.Chart.ChartTitle.Text & x & ".jpg"
           x = x + 1
       Next cht
       Next sht

End Sub
 
Last edited:

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
I don't see anything immediately and obviously wrong with your code. Why don't you explain what you mean by "but am a bit stuck"?
 
Upvote 0
Sure there are a couple of things for some reason after the Workbook named directory is created it then has an error if it's run.

Also creating separate folders for each tab name is quite tricky as I'm not sure where to put that in the code, and it would also have to recognise if those folders are already created it doesn't need to create them again.
 
Upvote 0
A good rule of thumb when asking for help with code is: Don't make people guess. There are many, many errors that excel is capable of generating so avoid general statements like "it has an error". If you get an error, describe which specific error you are getting. All runtime errors have a number and a description. If the error occurs at a specific line of code, tell us which line of code.
 
Upvote 0
Okay understand your point, I'll provide more detail tomorrow morning.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,203
Members
452,617
Latest member
Narendra Babu D

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