Advertisement

10.07.2008 at 09:25AM PDT, ID: 23794345 | Points: 500
[x]
Attachment Details

Code in 2003 Chart for embedded object to behave as trend line, makes code crash in 2007

Asked by Exl04 in Microsoft Excel Spreadsheet Software, Visual Basic Programming

Tags: , ,

I have a workbook with a chart that has 3 series, code (provided by ssaqibh) manipulates  3 objects (Arrows)  to behave as the chart trend lines (didnt wanted  3 lines across my chart it will be messy), the code work fine in the 2003 workbook, but user opening this workbook have Excel 2007 they are getting this error ;
Run-time error -2147467259(80004005)
Method XValue of the object Series failed

Any ideas?
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
Private Sub Worksheet_Activate()
 
Dim shp As Shape
Dim bShape As Boolean
Dim cht As ChartObject
Dim ser As Series
Dim AxisX As Axis, AxisY As Axis
Dim dX As Double, dY As Double, dSlope As Double, dAngle As Double
Dim xData As Variant, yData As Variant
Set cht = ActiveSheet.ChartObjects("chart 10")
Set AxisX = cht.Chart.Axes(xlCategory)
Set AxisY = cht.Chart.Axes(xlValue)
dX = AxisX.Width / (AxisX.MaximumScale - AxisX.MinimumScale)
dY = AxisY.Height / (AxisY.MaximumScale - AxisY.MinimumScale)
For sern = 1 To cht.Chart.SeriesCollection.Count
Set ser = cht.Chart.SeriesCollection(sern)
For Each shp In cht.Chart.Shapes
    Select Case sern
    Case 1
    shname = "redArrow"
    Case 2
    shname = "greenArrow"
    Case 3
    shname = "yellowArrow"
    End Select
    If shp.Name = shname Then
        Exit For
    End If
Next
With ser
    xData = .XValues
    yData = .Values
    dSlope = Application.WorksheetFunction.Slope(yData, xData) * dY / dX
    dAngle = 180 / Application.Pi() * Application.Atan2(1, dSlope)
    If dAngle < 0 Then dAngle = dAngle + 360
    shp.Rotation = -dAngle
End With
Next sern
End Sub
[+][-]10.17.2008 at 10:30AM PDT, ID: 22743173

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628