excel - More efficient way to write this script -


i printing lot of excel charts using vba. @ point have ~35 sheets print from, i'm wondering if there's script easier modify 1 working with.

sheets("euro graph").select activesheet.chartobjects("chart 1").activate activechart.plotarea.select activechart.pagesetup.rightheader = "nominal lcu" activechart.pagesetup.rightfooter = "&d  &t" activechart.pagesetup.centerfooter = "&a" activechart.pagesetup.leftfooter = "&z&f" selection.width = 921 selection.left = 23 selection.top = 61 selection.height = 550 activewindow.selectedsheets.printout copies:=1, collate:=true 

so works fine. each chart want print first select sheet, , activate chart want print referring chart number. there efficient way change chart printing specs (like changing header/footer) without manually having change every block of code use each chart?

edit: remove lot lines , have

sheets("euro graph").select activesheet.chartobjects("chart 1").activate activechart.pagesetup.rightheader = "nominal lcu" activewindow.selectedsheets.printout copies:=1, collate:=true 

but still able change "nominal lcu" , have affect code.

this tested, should show how loop through worksheets chartobjects, , how identify lcu chartobject:

sub setlcucharts() dim ws excel.worksheet dim chtobject excel.chartobject dim cht excel.chart  each ws in thisworkbook.worksheets     if ws.chartobjects.count > 0         each chtobject in ws.chartobjects             if instr(chtobject.name, "lcu") > 0                 set cht = ws.chartobjects(1).chart                 cht                     .pagesetup.rightheader = "nominal lcu"                     .printout copies:=1, collate:=true                 end             end if         next chtobject     end if next ws end sub 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -