Hi,

I am trying to delink my chart data because I get that annoying popup everytime I start up Excel 2000. I use the following code as a macro to assign to each of my charts, (got it from the jon pierre engineer's website from Google)

Anyways, my problem is that it still doesn't work. When I click my chart, it says it can be only used on chart objects. I do believe all my charts are chart objects. Has anyone got this code to work? thanks!

VB Code:
  1. Sub DelinkChartFromLotsOfData()
  2.  Dim nPts As Long, iPts As Long
  3.     Dim xArray As String, yArray As String
  4.     Dim xVals, yVals
  5.     Dim ChtSeries As Series
  6.     Dim iChars As Integer
  7.     Dim sChtName As String
  8.     Dim sSrsName As String
  9.     Dim iPlotOrder As Integer
  10.  
  11.     ''' Make sure a chart is selected
  12.     On Error Resume Next
  13.     sChtName = ActiveChart.Name
  14.     If Err.Number <> 0 Then
  15.         MsgBox "This functionality is available only for charts " _
  16.             & "or chart objects"
  17.         Exit Sub
  18.     End If
  19.     If TypeName(Selection) = "ChartObject" Then
  20.         ActiveSheet.ChartObjects(Selection.Name).Activate
  21.     End If
  22.     On Error GoTo 0
  23.  
  24.     ''' Loop through all series in active chart
  25.     For Each ChtSeries In ActiveChart.SeriesCollection
  26.         nPts = ChtSeries.Points.Count
  27.         xArray = ""
  28.         yArray = ""
  29.         xVals = ChtSeries.XValues
  30.         yVals = ChtSeries.Values
  31.         sSrsName = ChtSeries.Name
  32.         iPlotOrder = ChtSeries.PlotOrder
  33.  
  34.         For iPts = 1 To nPts
  35.             If IsNumeric(xVals(iPts)) Then
  36.                 ''' shorten numbers in X array (remove excess digits)
  37.                 iChars = WorksheetFunction.Max _
  38.                     (InStr(CStr(xVals(iPts)), "."), 5)
  39.                 xArray = xArray & Left(CStr(xVals(iPts)), iChars) & ","
  40.             Else
  41.                 ''' put quotes around string values
  42.                 xArray = xArray & """" & xVals(iPts) & ""","
  43.             End If
  44.  
  45.             ''' shorten numbers in Y array (remove excess digits)
  46.             iChars = WorksheetFunction.Max _
  47.                 (InStr(CStr(yVals(iPts)), "."), 5)
  48.  
  49.            ''' handle missing data - replace blanks and #N/A with #N/A
  50.            If IsEmpty(yVals(iPts)) Or WorksheetFunction.IsNA(yVals(iPts)) Then
  51.                yArray = yArray & "#N/A,"
  52.            Else
  53.                yArray = yArray & Left(CStr(yVals(iPts)), iChars) & ","
  54.            End If
  55.  
  56.         Next
  57.  
  58.         ''' remove final comma
  59.         xArray = Left(xArray, Len(xArray) - 1)
  60.         yArray = Left(yArray, Len(yArray) - 1)
  61.  
  62.         ''' Construct the new series formula
  63.         ChtSeries.Formula = "=SERIES(""" & sSrsName & """,{" & xArray & "},{" _
  64.             & yArray & "}," & CStr(iPlotOrder) & ")"
  65.     Next
  66. End Sub