Excel - Charts: Getting chart name - Missing value error

hello all,

I have a chart with the following data:

A B
1 100
2 200
3 300
4 400
5 500
6 600

–Title of chart: New Chart


tell application "Microsoft Excel"
	activate chart object 1
	get chart title text of chart object 1
end tell
-- Result: missing value
-- desired result "New Chart"

What I expected was “New Chart”

any help would be appreciatd.

Try something like this, slashdot:

tell application "Microsoft Excel"
	activate object chart object 1 of active sheet
	chart title text of chart title of active chart
end tell

thanks kai as always… that did it

I was wondering if you wanted to set a new name to that particular chart you wouldn’t know how to do that?

This should do the trick, slashdot:

tell application "Microsoft Excel"
	activate object chart object 1 of active sheet
	set chart title text of chart title of active chart to "Some Other Title"
end tell

Edit: Congratulations, slashdot - you’re my 500th customer! :wink:

You’re welcome and thanks for the great information as always…:slight_smile:

Kai,

I have the following code. Is there an script that can format the text of “Title_2” to font size 10 and “Title_3” to font size 9?


tell application "Microsoft Excel"
	set chartTitle to "Title_1\r" & "Title_2\r"& "Title_3"
	activate object chart object 1 of active sheet
	set chart title text of chart title of active chart to chartTitle
end tell

thanks for your help

We’re getting real fancy now, slashdot. :wink:

This should set the font sizes for lines 2 & 3 of the title:

set fontSize to {10, 9}
set chartTitle to "Title_1" & return & "Title_2" & return & "Title_3"

tell application "Microsoft Excel"
	activate object chart object 1 of active sheet
	set chart title text of chart title of active chart to chartTitle
	set r to count chartTitle's paragraph 1
	repeat with i from 2 to count chartTitle's paragraphs
		set l to r + 2
		set r to r + 1 + (count chartTitle's paragraph i)
		set font size of font object of characters l thru r of chart title of active chart to fontSize's item (i - 1)
	end repeat
end tell

And this slightly modified version should set font sizes for every line:

set fontSize to {12, 10, 9}
set chartTitle to "Title_1" & return & "Title_2" & return & "Title_3"

tell application "Microsoft Excel"
	activate object chart object 1 of active sheet
	set chart title text of chart title of active chart to chartTitle
	set r to -1
	repeat with i from 1 to count chartTitle's paragraphs
		set l to r + 2
		set r to r + 1 + (count chartTitle's paragraph i)
		set font size of font object of characters l thru r of chart title of active chart to fontSize's item i
	end repeat
end tell

Well just going with apple’s thought process. Thinking different. :slight_smile: Thanks kai as always you get exactly what I’m thinking.