如何使用Apple脚本在Excel中的图表上设置图表元素

时间:2012-11-08 06:02:06

标签: excel applescript

此脚本是通过错误“Microsoft Excel出错:工作表”活动工作簿的“sheet1”无法理解设置图表元素消息。“

tell application "Microsoft Excel"
    tell worksheet "Sheet1" of active workbook
        set ochart1 to chart of chart object 1
           tell ochart1
               set chart element chart element 1
               --- create the chart title on chart with value 1
           end tell
    end tell
end tell

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:1)

这也有效。为什么要使用set chart element命令创建图表标题?

tell application "Microsoft Excel"
    tell worksheet "Sheet1" of active workbook
        set ochart1 to chart of chart object 1
        tell ochart1
            set chart title text of it's chart title to "My Title"
        end tell
    end tell
end tell

答案 1 :(得分:0)

如果你想创建一个图表标题,这对我有用:

tell application "Microsoft Excel"
    tell worksheet "Sheet1" of active workbook
        set ochart1 to chart of chart object 1
        tell ochart1
            set has title to true                       
            set caption of its chart title to "your title here"         
        end tell
    end tell
end tell