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:

  1. the .caption = "=newchartsheet!r1c1" sets chart title equal value in cell a1
  2. the ws.range("a1").formula sets formula show sheet name.
  3. the formula in a1 uses filename argument of cell function, returns full file path, file name , sheet name, of referenced cell.
  4. the formula manipulates format of filename further return sheet name.

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -