I'm adding a chart via vba with the following commands:
Dim CsvVisualization As ChartObject
Set ChartSizePosition = Range("B8:I25")
Set CsvVisualization = ThisWorkbook.Sheets("Übersicht").ChartObjects.Add(ChartSizePosition.Left, ChartSizePosition.Top, ChartSizePosition.Width, ChartSizePosition.Height)
CsvVisualization.Name = "MeasurementVisualization"
With CsvVisualization.Chart
.ChartType = xlXYScatterSmoothNoMarkers
...
How could I proofe if this chart was already created when the excel file is reopened? I tried something like:
If CsvVisualization Is Nothing Then
But CsvVisualization won't hold it's value when the file is closed and opened again.
Thank you for help!
Dim CsvVisualization As ChartObject
Dim MyChartName as string
Dim CreateChart as Boolean
MyChartName = "MeasurementVisualization"
CreateChart = True
If ThisWorkbook.Sheets("Übersicht").ChartObjects.Count = 0 Then
For Each CsvVisualization in ThisWorkbook.Sheets("Übersicht").ChartObjects
If CsvVisualization.name = MyChartName then
CreateChart = False
End If
Next
End if
If CreateChart then
Set ChartSizePosition = Range("B8:I25")
Set CsvVisualization = ThisWorkbook.Sheets("Übersicht").ChartObjects.Add(ChartSizePosition.Left, ChartSizePosition.Top, ChartSizePosition.Width, ChartSizePosition.Height)
CsvVisualization.Name = "MeasurementVisualization"
With CsvVisualization.Chart
.ChartType = xlXYScatterSmoothNoMarkers
...
End If
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With