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

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
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,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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