ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  How to add a chart to Excel sheet with VBA code
Posted by Alexx on Feb-09-2016 05:23
If add a chart manually, enable recording macros, I get something like this:

Me.OLEObjects.Add(ClassType:="CDChartViewer.ChartViewer", Link:=False, DisplayAsIcon:=False, Left:=332.25, Top:=123, Width:=397.5, Height:=276)

This is the correct way? Is there a better way?

  How to add a chart to Excel sheet with VBA code
Posted by Alexx on Feb-09-2016 05:34
This is my code:

...........
Me.OLEObjects.Add ClassType:="CDChartViewer.ChartViewer", Link:= _
        False, DisplayAsIcon:=False, Left:=417.75, Top:=99.75, Width:=272.25, Height:=199.5

    Set chrt = Me.OLEObjects("ChartViewer1").Object

    Set chrt.Picture = C.makePicture()
...........

there may be a more correct method?

  Re: How to add a chart to Excel sheet with VBA code
Posted by Peter Kwan on Feb-09-2016 12:40
Hi Alexx,

Usually, I will just drag the control to the surface of the spreadsheet. If I need one or a
few controls dynamically, I will drag them to the spreadsheet and hide them. When the
code needs them, it can make them visible.

I have just tried your code to dynamically create the controls, and it works in my case
after I added one more line at the end:

Me.Select

Regards
Peter Kwan