Jump to content

Delete Chart in Excel

Recommended Posts


I found this link on how to add charts in Excel, http://www.autoitscript.com/forum/index.php?showtopic=21371&st=0&p=148537&hl=chartobject&fromsearch=1&#entry148537

My problem right now is how to delete the created chart?

I'm having multiple overlapping charts everytime I run the script.

Snippet of Chart Generation Script <-- This works, I was able to generate charts with no problems.

$oExcel.ActiveSheet.ChartObjects.Add(1350, 30, 300, 300).Select

$oExcel.ActiveChart.ChartWizard($oExcel.Sheets($SheetName).Range($oRange), $xlLine, 4, $xlRows, 1, $Column, 1, $SheetName, $xLabel, $yLabel)

Snippet of Chart Deletion Script <-- this doesn't work, I cannot delete charts embedded on the excel file.

$ChartCount = $oExcel.ActiveSheet.ChartObjects.Count ;i was able to count the number of embedded charts successfully.

If $ChartCount > 0 Then

For $j = 0 to $ChartCount

$oExcel.ActiveSheet.ChartObjects($j + 1).Delete ;this line returns an error.

$j = $j +1



After saving and closing the excel file, no changes was done on the file.

I get this error:

$oExcelReport.ActiveSheet.ChartObjects($j + 1).Delete

$oExcelReport.ActiveSheet.ChartObjects($j + 1)^ ERROR

->17:00:27 AutoIT3.exe ended.rc:1

+>17:00:28 AutoIt3Wrapper Finished

Any idea? I have been researching and working on this the whole day with no luck.

Link to comment
Share on other sites

This works for me

$iChartCount = $oExcel.ActiveSheet.ChartObjects.Count
If $iChartCount > 0 Then
    For $j = 1 to $iChartCount

really? tested this again, no luck.


$oExcelReport.ActiveSheet.ChartObjects($j)^ ERROR

->08:53:31 AutoIT3.exe ended.rc:1

I'm using Office 2007, can that be the issue?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...