D
drako
Hi,
I'm currently trying to figure out how to dynamically create and insert
an Excel Chart into a Word Document, based upon several paramaters that
are selected within a Word VBA Userform.
I've looked at inserting an OLE Object, or firing up Excel from Word,
passing the paramaters to a VBA Macro, then generating the chart.
On the surface, using an OLE Object from Word looks easier. I would use
the following code to generate an exploded pie chart:
Sub pie_chart()
Selection.InlineShapes.AddOLEObject ClassType:="Excel.Chart.8",
FileName:= _
"", LinkToFile:=False, DisplayAsIcon:=False
End Sub
However, I have no idea how to pass data to object once it has been
created.
If I was to generate a chart in Excel from VBA code, I would use
something like:
Sub pie_chart()
Range("A3:B7").Select
Charts.Add
ActiveChart.ChartType = xl3DPieExploded
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A3:B7"),
PlotBy:= _
xlColumns
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Recommended Asset Allocation"
End With
ActiveChart.ApplyDataLabels Type:=xlDataLabelsShowPercent,
LegendKey:=False _
, HasLeaderLines:=False
End Sub
I suspect that I would need to use similar code to that above to fine
tune the chart, but really am unsure how I would pass it to the OLE
generated chart.
Any suggestions or tips appreciated.
Rgds
Neil.
I'm currently trying to figure out how to dynamically create and insert
an Excel Chart into a Word Document, based upon several paramaters that
are selected within a Word VBA Userform.
I've looked at inserting an OLE Object, or firing up Excel from Word,
passing the paramaters to a VBA Macro, then generating the chart.
On the surface, using an OLE Object from Word looks easier. I would use
the following code to generate an exploded pie chart:
Sub pie_chart()
Selection.InlineShapes.AddOLEObject ClassType:="Excel.Chart.8",
FileName:= _
"", LinkToFile:=False, DisplayAsIcon:=False
End Sub
However, I have no idea how to pass data to object once it has been
created.
If I was to generate a chart in Excel from VBA code, I would use
something like:
Sub pie_chart()
Range("A3:B7").Select
Charts.Add
ActiveChart.ChartType = xl3DPieExploded
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A3:B7"),
PlotBy:= _
xlColumns
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Recommended Asset Allocation"
End With
ActiveChart.ApplyDataLabels Type:=xlDataLabelsShowPercent,
LegendKey:=False _
, HasLeaderLines:=False
End Sub
I suspect that I would need to use similar code to that above to fine
tune the chart, but really am unsure how I would pass it to the OLE
generated chart.
Any suggestions or tips appreciated.
Rgds
Neil.