ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   changing chart title via vba? (https://www.excelbanter.com/excel-programming/280061-changing-chart-title-via-vba.html)

basis

changing chart title via vba?
 
I don't understand why this is so difficult, but I'm trying to change
the title bar of a chart. I couldn't get the code to work, so I just
recorded a simple macro to see a "working" version. Problem is, the
recorded macro doesn't work either!

Here's the code from the macro:

Sub Macro1()
Sheets("3. FHS").Select
ActiveSheet.ChartObjects("ProjGraph1").Activate
ActiveChart.ChartTitle.Select
Selection.Characters.Text = "Text"
End Sub

When I press play from within the editor, I get:

Run-time error '-2147221080 (800401a8)':
Method'ChartTitle' of object'_Chart' failed

This should be so simple, but as a newbie, I'm making no progress
whatsoever ....

b



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/


Greg Wilson[_4_]

changing chart title via vba?
 
The following assumes that the chart is the first that was
added to the worksheet and therefore is referred to as
Chartobjects(1). Change the index number if necessary.
Note that there is no need to select anything.

Sub Macro1()
ActiveSheet.ChartObjects(1).Chart. _
ChartTitle.Characters.Text = "Text"
End Sub

-----Original Message-----
I don't understand why this is so difficult, but I'm

trying to change
the title bar of a chart. I couldn't get the code to

work, so I just
recorded a simple macro to see a "working" version.

Problem is, the
recorded macro doesn't work either!

Here's the code from the macro:

Sub Macro1()
Sheets("3. FHS").Select
ActiveSheet.ChartObjects("ProjGraph1").Activate
ActiveChart.ChartTitle.Select
Selection.Characters.Text = "Text"
End Sub

When I press play from within the editor, I get:

Run-time error '-2147221080 (800401a8)':
Method'ChartTitle' of object'_Chart' failed

This should be so simple, but as a newbie, I'm making no

progress
whatsoever ....

b



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from

http://www.ExcelForum.com/

.


Tom Ogilvy

changing chart title via vba?
 
Try it like this:

Sub Macro1()
With Sheets("3. FHS").ChartObjects("ProjGraph1")
.Chart.HasTitle = True
.Chart.ChartTitle.Text = "This is New Title"
End With
End Sub

--
Regards,
Tom Ogilvy

"basis" wrote in message
...
I don't understand why this is so difficult, but I'm trying to change
the title bar of a chart. I couldn't get the code to work, so I just
recorded a simple macro to see a "working" version. Problem is, the
recorded macro doesn't work either!

Here's the code from the macro:

Sub Macro1()
Sheets("3. FHS").Select
ActiveSheet.ChartObjects("ProjGraph1").Activate
ActiveChart.ChartTitle.Select
Selection.Characters.Text = "Text"
End Sub

When I press play from within the editor, I get:

Run-time error '-2147221080 (800401a8)':
Method'ChartTitle' of object'_Chart' failed

This should be so simple, but as a newbie, I'm making no progress
whatsoever ....

b



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/





All times are GMT +1. The time now is 05:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com