Hello:
I'm having trouble creating a pivot chart using vbscript. I have a vbscript
that pulls info from AD and dumps it into Excel. I currently add the pivot
chart manually to each report, but wanted to automate it. Is this possible?
Oooh, my first occasion to return the help I received on the ng
First of all, what's AD?
Pivot charts are very easy, but Pivot Tables (from which Pivot Charts
are created) are not so simple, so you might want to play with the
Macro recorder for some time before writing your own macro. Anyway, I
assume that you already know about PivotCaches, PivotTables and all
that jazz. Let's go straight to Pivot Charts:
Sub AddPivotChart(PT As PivotTable, ChartName As String, cht As Chart)
' Add a PivotChart associated with PivotTable PT
' First of all, create a chart sheet for your Pivot Chart: I have my
own "safe" Add Chart routine,
' you can use yours or just use the Charts.Add method, even though
that's no so safe
Call AddChart(ChartName, cht)
With cht
'Pivot Chart Name
.Name = ChartName
'A Chart becomes a Pivot Chart, basically, when you set the
SourceData to a PivotTable
.SetSourceData Source:=PT.TableRange1
'Add title
.HasTitle = True
.ChartTitle.text = ChartName
'Change format to what suits your chart best
.ChartType = xlLineMarkers
End With
End Sub
Hope this helps,
Sergio Rossi (deltaquattro)