Saving Chart Data and error handling

Status
Not open for further replies.

Tech1_uk

New Member
Joined
Sep 22, 2018
Messages
17
Hi All,

I have command button that will save chart from a sheet as a jpg file.(Ifound this code on this Forum) This is working OK but I need to make sure the file is saved to the users desktop. I pretty sure the code I have used is OK for this but I won't mind someone checking it please. Currently the file will overwrite a existing file of the same name without a prompt.

May be it is best if the user can select their own filename and location, but I have no idea where to start with that, but that would fix the 2 problems above.

Also currently if the sheet"Charts" doesn't exist it will error, I need a msgbox and then return to the userform.

Any help would be great.

Cheers

Code:
Private Sub CommandButton6_Click()
Dim objChrt As ChartObject
Dim myChart As Chart


    Set objChrt = Sheets("Chart").ChartObjects(1)
    Set myChart = objChrt.Chart


    myFileName = "Cell Data.jpg"


    On Error Resume Next
    Kill ThisWorkbook.Path & "\" & myFileName
    On Error GoTo 0


myChart.Export Filename:=myFileName, Filtername:="jpg"
    MsgBox "File Cell Data.jpg has been saved to the desktop", vbInformation


End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Duplicate https://www.mrexcel.com/forum/excel...ng-chart-data-error-handling.html#post5151228

Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread.
Per forum rules, posts of a duplicate nature will be locked or deleted (rule 12 here: Forum Rules).

Note that sometimes posts from new users require Moderator approval before you can see them on the public forums. When this happens, you should see a message to that effect when you try to post it.
Please be patient and do not attempt to post the question again.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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