Hi,
Sometimes in VBA it's necessary to make sure that the property of an object exists before attempting to apply code to it.
For example, I'd like to set the chart title to "Awesome Chart" regardless of whether the chart already has a title or not.
However if the chart doesn't have a title the c.charttitle.characters will fail. How do I test to see if .Characters exist before calling its .text property?
I know I can do On Error Goto, but that seems like a back-door approach to a front-door problem.
Sometimes in VBA it's necessary to make sure that the property of an object exists before attempting to apply code to it.
For example, I'd like to set the chart title to "Awesome Chart" regardless of whether the chart already has a title or not.
Code:
Sub Add Chart()
Dim C As Chart
For Each c In ThisWorkbook.Charts
c.ChartTitle.Characters.Text = "5"
End If
End Sub
However if the chart doesn't have a title the c.charttitle.characters will fail. How do I test to see if .Characters exist before calling its .text property?
I know I can do On Error Goto, but that seems like a back-door approach to a front-door problem.