Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
I have the following code - ' Sheet 1 Dim temp As Klass1 Private Sub CommandButtonCreateObject_Click() Set temp = New Klass1 End Sub Private Sub CommandButtonTest_Click() Dim myButton As New OLEObject Dim CurSheet As Worksheet Cells(1, 1) = temp.GetTemp Set CurSheet = Worksheets("Sheet1") Set myButton = ActiveSheet.OLEObjects.Add(ClassType:="Forms.Comma ndButton.1") Cells(1, 2) = temp.GetTemp End Sub 'Klass1 Private tmp1 As Integer Sub Class_Initialize() tmp1 = 10 End Sub Function GetTemp() As Integer GetTemp = tmp1 End Function I have 2 button on my worksheet in order to trigger CommandButtonTest_Click() and Class_Initialize() respectfully. So first I press the CreateObject button first and then I should be able to press Test button multiple times. The problem though is that when I press the Test button the 2nd time, I get an error. This is because temp has been reset to Nothing. Why might this happen? Also, the number 10 is being printed to both cells so it seems that temp is set to nothing at the end of the CommandButtonTest_Click() function. Commenting out the line - Set myButton = ActiveSheet.OLEObjects.Add(ClassType:="Forms.Comma ndButton.1") causes everything to work fine except for the button not being created. When I place a breakpoint error on this line, I get a error stating that the breakpoint cannot be used just now (this error is given in Swedish so I can't give you the english version...), with the option to terminate or continue. Either way temp is being reset each time CommandButtonTest_Click() is called and ActiveSheet.OLEObjects.Add seems to be the culprit. Any ideas? Thanks, Barry. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Interval accumulation and resets | Excel Discussion (Misc queries) | |||
Udf resets on 3rd workbook | Excel Programming | |||
Globals set to nothing | Excel Programming | |||
Copying new activesheet after other activesheet is hidden? | Excel Programming |