gingerbytes Posted January 11, 2010 Share Posted January 11, 2010 hi,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 NextEndIfAfter 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 FinishedAny idea? I have been researching and working on this the whole day with no luck. Link to comment Share on other sites More sharing options...
picaxe Posted January 11, 2010 Share Posted January 11, 2010 This works for me$iChartCount = $oExcel.ActiveSheet.ChartObjects.Count If $iChartCount > 0 Then For $j = 1 to $iChartCount $oExcel.ActiveSheet.ChartObjects($j).Delete Next EndIf Link to comment Share on other sites More sharing options...
gingerbytes Posted January 12, 2010 Author Share Posted January 12, 2010 This works for me$iChartCount = $oExcel.ActiveSheet.ChartObjects.Count If $iChartCount > 0 Then For $j = 1 to $iChartCount $oExcel.ActiveSheet.ChartObjects($j).Delete Next EndIf really? tested this again, no luck. $oExcelReport.ActiveSheet.ChartObjects($j).Delete $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 More sharing options...
gingerbytes Posted January 12, 2010 Author Share Posted January 12, 2010 I Got this to work While $oExcel.ActiveSheet.ChartObjects.Count $oExcel.ActiveSheet.ChartObjects($oExcel.ActiveSheet.ChartObjects.Count).Delete WEnd This issue has been solved! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now