LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default ActiveSheet.OLEObjects.Add resets globals to Nothing

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Interval accumulation and resets Tom Excel Discussion (Misc queries) 1 December 17th 07 05:47 PM
Udf resets on 3rd workbook Denis Excel Programming 1 July 20th 07 12:55 AM
Globals set to nothing fijimf Excel Programming 1 November 27th 06 08:58 PM
Copying new activesheet after other activesheet is hidden? Simon Lloyd[_790_] Excel Programming 1 June 20th 06 10:02 AM


All times are GMT +1. The time now is 09:49 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"