adding control at runtime in Excel using VBA

TeeChart for ActiveX, COM and ASP
Post Reply
dilly
Newbie
Newbie
Posts: 1
Joined: Tue Jul 26, 2005 4:00 am

adding control at runtime in Excel using VBA

Post by dilly » Wed Apr 05, 2006 10:55 am

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

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Tue Apr 11, 2006 9:39 am

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)
?

Post Reply