Sub Run-time error

P

Phil Hageman

The following sub is suppose to make a list of all charts
in a worksheet. When running the sub, I get Run-time
error '1004': Unable to get the Caption property of the
ChartTitle class. The line Msg = Msg & vbCrLf... is
highlighted. Can someone help me fix this.

Sub ListCharts()
Dim Msg As String
Dim ChtOb As ChartObject
Msg = ActiveSheet.Name & vbCrLf
For Each ChtOb In ActiveSheet.ChartObjects
Msg = Msg & vbCrLf & ChtOb.Name & " : " &
ChtOb.Chart.ChartTitle.Caption
Next
MsgBox Msg
End Sub
 
T

Tom Ogilvy

Sub ListCharts()
Dim Msg As String
Dim ChtOb As ChartObject
Msg = ActiveSheet.Name & vbCrLf
For Each ChtOb In ActiveSheet.ChartObjects
if chtOb.HasTitle then
Msg = Msg & vbCrLf & ChtOb.Name & " : " & _
ChtOb.Chart.ChartTitle.Caption
Else
Msg = Msg & vbCrLf & chtOb.Name & ":" & _
"No title"
End if
Next
MsgBox Msg
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top