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