I have a VBA application in an Excel Workbook. At the end of the sub I need to delete a chart. In old version of Excel (2013), method "delete" of chart sheet works perfectly. In version 2019 now this method is not supported and I can't find anything on Microsoft website.
Could you help me if exist new method to delete chart sheets?
This is the piece of code at the end of sub
For Each sht In Workbooks(Nam).Sheets
If sht.name <> "Config" Then
Workbooks(Nam).Sheets(sht.name).Delete
End If
Next
When is selected the chart sheet I receive this error:
Run-time errore '1004': Error in method Delete of Chart class
Thanks
It sounds as though you just need to delete the chart sheets from the workbook. I agree that your code looks as though it would, but here is a slightly different approach that may work in your environment.
VBA has three collections for working with sheets in a workbook. Sheets is a collection of all sheets regardless if they are worksheets or chart sheets. Worksheets is the collection of all worksheets. Charts is the collection of all charts. The code below deletes all chart sheets from the current workbook.