Option
Explicit
Sub
CreateChart()
Dim
objSh
As
Shape
Set
objSh = ActiveSheet.Shapes.AddChart2(227, xlLine)
objSh.Chart.SetSourceData Source:=ThisWorkbook.Names(
"Daten"
).RefersToRange
objSh.Left = 200
objSh.Top = 10
chartID = objSh.ID
End
Sub
Sub
RefreshChart()
Dim
wsh
As
Worksheet
Dim
ch
As
ChartObject
Set
wsh = ActiveSheet
For
Each
ch
In
wsh.ChartObjects
If
ch.ShapeRange.ID = chartID
Then
ch.Delete
CreateChart
Exit
For
End
If
Next
End
Sub
Property
Get
chartID()
As
Integer
Dim
wsh
As
Worksheet
Dim
iProp
As
Integer
Set
wsh = ActiveSheet
For
iProp = 1
To
wsh.CustomProperties.Count
If
wsh.CustomProperties.Item(iProp).Name =
"Chart"
Then
chartID = Val(wsh.CustomProperties.Item(iProp).value)
Exit
For
End
If
Next
End
Property
Property
Let
chartID(value
As
Integer
)
Dim
wsh
As
Worksheet
Dim
bExists
As
Boolean
Dim
iProp
As
Integer
Set
wsh = ActiveSheet
For
iProp = 1
To
wsh.CustomProperties.Count
If
wsh.CustomProperties.Item(iProp).Name =
"Chart"
Then
wsh.CustomProperties.Item(iProp).value = value
bExists =
True
Exit
For
End
If
Next
If
Not
bExists
Then
wsh.CustomProperties.Add
"Chart"
, value
End
If
End
Property