Page 1 of 1

adding control at runtime in Excel using VBA

Posted: Wed Apr 05, 2006 10:55 am
by 9527828
what is the correct way to add the control at runtime?

In excel using VBA i use this:

Dim oleObj As OLEObject
Dim strChartName As String

strChartName = "something"

Set oleObj = ActiveSheet.OLEObjects.Add(ClassType:="TeeChart.TChart", Left:=150, Top:=300Width:=500Height:=375)

oleObj.name = strChartName

when i step through the code i get a run time error 438 at the set oleObj line and the execution ends. However, the chart object is created on the sheet and it does take the name as specified in strChartName.

but the following code is never reached
Dim tcChart As teechart.TChart
Set tcChart = oleObj.OLEFormat.Object.Object
tcChart.RemoveAllSeries
tcChart.AddSeries scLine
etc. etc..

i am using version 7.0.0.7 of TeeChart7.ocx

thanks for any pointers

Posted: Tue Apr 11, 2006 9:39 am
by Pep
Hi,

how about using the following code :

Code: Select all

Set TChart = ActiveSheet.OLEObjects.Add(ClassType:="TeeChart.TChart",
Link:=False, _

        DisplayAsIcon:=False, Left:=fLeft, Top:=fTop, Width:=fWidth,
Height:=fHeight)
?