Interesting VBA problem.

xamination

New Member
Joined
Jul 8, 2011
Messages
5
I am writing a program which takes data from multiple charts and combines them into one singular chart. Everything seems to be working fine, until I get to these last two lines

ActiveChart.HasTitle = True
ActiveChart.ChartTitle.Text = chartName

Now, if I run the macro as is, I get an error message telling me "The object has no title." Hovering over ActiveChart.HasTitle says it is set at false. HOWEVER, if I put a stop in a few lines before, and step through these lines, everything works fine, no problem. I even put a do until loop around "activechart.hastitle = true" to make sure it was setting it to true.

It seems that if I run through it as normal it will throw an error. But if I step through it it won't. Whats causing this error, or what would be a work around at least?

Thanks in advance
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Sometimes things get a little strange depending on whether what you have is a chart or a chart object. Try the following:

Code:
ActiveChart.chart.HasTitle = True
ActiveChart.chart.ChartTitle.Text = chartName

If that fails - try binding an object variable to the chart instead of trying to use the ActiveChart object and do your manipulations on the bound chart-object variable.
 
Upvote 0
Tried all the methods you suggested, nothing has worked. For whatever reason the hasTitle value keeps being set to False, no matter what I do to set it True...
Anyone else have any ideas?
 
Upvote 0
But you can go in and do what you want to do manually? It's not a case where it's actually not possible. Just a case where VBA is being cantankerous?
 
Upvote 0
"cantankerous"? Nice word. And yes. If I step through the lines of code, there seems to be no problem. But when it runs on it's own, it just... decides to be difficult.
 
Upvote 0
Had the exact same problem today, did this and it worked fine ( I am using excel 2010)

instead of
ActiveChart.HasTitle = True

use
ActiveChart.SetElement (msoElementChartTitleAboveChart)

this worked for me when running the code.
 
Upvote 0
The .SetElement(...) method. Still have no idea why I was getting the problem I was, but it's water under the bridge IMO
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top