Couple points:
1. In the VB Editor, select Options from the Tools menu, and on the Editor tab,
check Require Variable Declarations. This puts "Option Explicit" at the top of your
modules, and forces you to declare (Dim) your variables.
2. Your code is adding a line to the worksheet, not to the chart. THis makes
positioning even more difficult. My code below adds the line to the chart within the
chart object, so at least it moves with the chart (but won't resize properly).
Sub DrawDiag()
Dim PlotAreaOffsetX As Single
Dim PlotAreaOffsetY As Single
Dim ChartSizeX As Single
Dim ChartSizeY As Single
With Worksheets(1).ChartObjects(1).Chart
'Get Chart Size
ChartSizeX = .PlotArea.InsideWidth
ChartSizeY = .PlotArea.InsideHeight
'Get Chart Position
PlotAreaOffsetX = .PlotArea.InsideLeft
PlotAreaOffsetY = .PlotArea.InsideTop
'Draw the line
With .Shapes.AddLine(PlotAreaOffsetX, PlotAreaOffsetY, _
PlotAreaOffsetX + ChartSizeX, PlotAreaOffsetY + ChartSizeY)
.Line.Parent.Name = "line"
End With
End With
End Sub
- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______