excel - How to refer to chart title in Shapes()? -
i want format chart in new tab based on existing data worksheet. can record pattern using "save template", want create macro creates same format every time. however, have problem referring chart. here's code.
sub macro1() dim graphtab object set graphtab = activesheet 'change times new roman activesheet.shapes(graphtab).textframe2.textrange.font .namecomplexscript = "times new roman" .namefareast = "times new roman" .name = "times new roman" .size = 10 end end sub i receive error message starting line with activesheet.shapes(graphtab).textframe2.textrange.font.
ideally, want graphtab updated every time manually change tab name. possible?
based on last comment, code has been tested produce desired results.
sub macro1() dim ws worksheet set ws = sheets("newchartsheet") ' change name needed ws.range("a1").formula = "=right(cell(""filename"",a1),len(cell(""filename"",a1))-find(""]"",cell(""filename"",a1))) dim cht chartobject set cht = ws.chartobjects(1) 'since 1 chart on page, it's first 1 in collection cht.chart.charttitle .format.textframe2.textrange.font .namecomplexscript = "times new roman" .namefareast = "times new roman" .name = "times new roman" .size = 10 end .caption = "=newchartsheet!r1c1" end end sub to understand how chart title set automatically change if sheet name changed see below:
- the
.caption = "=newchartsheet!r1c1"sets chart title equal value in cell a1 - the
ws.range("a1").formulasets formula show sheet name. - the formula in
a1usesfilenameargument of cell function, returns full file path, file name , sheet name, of referenced cell. - the formula manipulates format of filename further return sheet name.
Comments
Post a Comment