vba - Using VBScript to change background color in Excel chart -
i'm using vbscript create line scatter plot columns of data in excel 2003. comes out fine, want edit of properties of chart, such background color , axis labels. did manually in excel , recorded macro, gave me following vba code:
activechart.plotarea.select selection.border     .colorindex = 16     .weight = xlthin     .linestyle = xlcontinuous end with selection.interior     .colorindex = 2     .patterncolorindex = 1     .pattern = xlsolid end activechart.axes(xlcategory).select selection.ticklabels     .readingorder = xlcontext     .orientation = 45 end activechart.axes(xlvalue).axistitle.select selection     .horizontalalignment = xlcenter     .verticalalignment = xlcenter     .readingorder = xlcontext     .orientation = xlhorizontal end activechart.chartarea.select end sub
this looks fine vba, i'm having trouble converting vbscript. how should started? code @ moment:
set objchart = objexcel.charts.add() objexcel.activechart     .charttype = xlxyscatterlinesnomarkers     .seriescollection(1).interior.color = rgb(255, 0, 0)     .hastitle = true     .charttitle.text = "usage"     .axes(xlcategory, xlprimary).hastitle = true     .axes(xlcategory, xlprimary).axistitle.characters.text = "time"     .axes(xlvalue, xlprimary).hastitle = true     .axes(xlvalue, xlprimary).axistitle.characters.text = "units"     .haslegend = false     .setsourcedata objworksheet.range("e1","f" & lastrow), xlcolumns     .setsourcedata objworksheet.range("e1:f200"), xlcolumns end the line .seriescollection(1).interior.color = rgb(255, 0, 0) causes error: "unable set color property of interior class". i'm guessing shouldn't call .seriescollection right under .activechart. suggestions? @ point i'd happy able change background color of chart white, , rotate x-axis labels 45 degrees.
thank in advance.
order matters. before can access series, have add first. same goes other properties, hastitle. also, lines of xy diagram don't have interior color, that's available in charts show interior (like pie charts or column charts). mean border color here. change code this:
set objchart = objexcel.charts.add objchart   ' define chart type   .charttype = xlxyscatterlinesnomarkers    ' define data   .setsourcedata objworksheet.range("e1:f200"), xlcolumns    ' format chart   .seriescollection(1).border.color = rgb(255, 0, 0)   .plotarea.interior.color = rgb(255, 255, 255)   '.plotarea.interior.colorindex = 2  'alternative   .hastitle = true   .charttitle.text = "usage"   .axes(xlcategory, xlprimary).hastitle = true   .axes(xlcategory, xlprimary).axistitle.characters.text = "time"   .axes(xlvalue, xlprimary).hastitle = true   .axes(xlvalue, xlprimary).axistitle.characters.text = "units"   .haslegend = false end and should work, provided have defined symbolic constants.
Comments
Post a Comment