Consulting

Results 1 to 4 of 4

Thread: Solved: Delete Embedded Charts

  1. #1
    VBAX Regular
    Joined
    May 2006
    Posts
    67
    Location

    Solved: Delete Embedded Charts

    I have tried to find a solution to the following problem without much success.

    I have an application that creates a number of charts each time it is run. What I need to do is delete any charts that currently exist from the previous time it was run. I could re name each new chart when it is created but I am not really bothered about the charts name I just want to delete any existing charts and let Excel default the name.

    The code I have is;

    Sub delete_charts()
    Dim graph As Excel.Chart
    For Each graph In ThisWorkbook.Charts
    graph.Delete
    Next
    End Sub

    It runs without erroring but fails to delete any existing charts

    Any help would be much appreciated

  2. #2
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    try this:

    [VBA]


    ActiveWorkbook.Charts.Delete

    [/VBA]

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Sub DeleteAllCharts()
    Dim sh As Worksheet
    Application.DisplayAlerts = False
    'Delete chart sheets
    ActiveWorkbook.Charts.Delete
    'Delete embedded charts
    For Each sh In Worksheets
    sh.ChartObjects.Delete
    Next
    Application.DisplayAlerts = True
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    VBAX Regular
    Joined
    May 2006
    Posts
    67
    Location
    Thanks Malcolm,

    Yet again you come up trumps.

    Thanks very much for the solution, it's much appriecated I have tried all day to get an answer before posting an enquiry

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •