473,788 Members | 3,078 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Class modules with OLEObject kill own instances

1 New Member
The goal : to have class which is able to add some OLE objects on the sheet runtime. Instances of the class must be accessible from any public/private module.

Okay, I've experimented for so long & getting quite tired (:huh: ) of it. So I think it's time to call some help. I hope there must be some solution. I NEED it.

Well actually what I need ? I need to have some class/object which create some OleObjects (images and buttons) runtime. Instances of the class must be accessible from any module as global object.

Object must becreated inside the Private Sub Workbook_Open() event or via Public Sub Auto_Open() in module. Inside the class are some function/procedures for adding CommandButtons on the sheet.

Sounds pretty easy and should be. But the reality is else (strange :-))...

Everytime I call some of the procedure which works with OLE objects (adding/deleting - I mean Add method) all instances of the class are killed. I'd REALLY like to know what's killing them ???

Without OLE procedures all seems to be working fine - the instances of the class stay alive for all the Excel/workbook session. So problem must be with OLEobjects. But I want to be able working with the OLE objects...

Now I'll provide simplified skeleton of the code of my project:

Modules :: Module1

Expand|Select|Wrap|Line Numbers
  1.  
  2. Option Explicit
  3.  
  4. Public ole_obj_img As TOle_object_image
  5.  
  6. Public Static Function New_TOle_object_image() As TOle_object_image
  7.     Set New_TOle_object_image = New TOle_object_image
  8. End Function
  9.  
  10. Public Sub Auto_Open()
  11.  
  12.     Set ole_obj_img = New_TOle_object_image
  13.  
  14.     ole_obj_img.sheet_idx = 1
  15.  
  16.     ole_obj_img.add_image                   'calling this cause destruction of the object (why ?)
  17.  
  18.     'ole_obj_img.inc_counter offset:=10  'this work fine; no OLE inside
  19.  
  20. End Sub
  21.  
  22.  
Modules :: Module2

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Sub alpha()
  3.  
  4.     ole_obj_img.sheet_idx = 2
  5.     'other code
  6.  
  7. End Sub
  8.  
  9. Private Sub betta()
  10.  
  11.     ole_obj_img.sheet_idx = 1
  12.     'other code
  13.  
  14. End Sub
  15.  
  16.  

Class Modules :: TOle_object_ima ge
(Instancing = Private)

Expand|Select|Wrap|Line Numbers
  1.  
  2. Option Explicit
  3.  
  4. Private sh_idx As Integer
  5. Dim count As Integer
  6. Dim count_removed As Integer
  7. Private w As Worksheet
  8.  
  9. Private Sub Class_Initialize()
  10.     'constructor
  11.     sh_idx = 0
  12.     count = 0
  13.     count_removed = 0
  14.     MsgBox "TOle_object_image initialized"  'only for debug
  15. End Sub
  16.  
  17. Private Sub Class_Terminate()
  18.     'destructor
  19.     MsgBox "TOle_object_image terminated"  'only for debug
  20. End Sub
  21.  
  22. Property Let sheet_idx(uIdx As Integer)
  23.     sh_idx = uIdx
  24. End Property
  25.  
  26. Property Get sheet_idx() As Integer
  27.     sheet_idx = sh_idx
  28. End Property
  29.  
  30. Public Static Sub inc_counter(ByVal offset As Integer)
  31.     count = count + offset
  32. End Sub
  33.  
  34. Public Static Sub add_image()
  35.     Dim tmp_ole As OLEObject
  36.     Dim i As Integer
  37.     Dim wo As OLEObjects
  38.  
  39.     i = 0           
  40.  
  41.     Set wo = ThisWorkbook.Worksheets(sh_idx).OLEObjects
  42.  
  43.         wo.Add ClassType:="Forms.Image.1", _
  44.             DisplayAsIcon:=False, Left:=10 + 30 * i, Top:=10 + 30 * i, Width:=20, Height:=20
  45.  
  46.     Set wo = Nothing
  47.     count = count + 1
  48. End Sub
  49.  
  50.  
Workbook code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Workbook_BeforeClose(Cancel As Boolean)
  3.        Set ole_obj_img = Nothing
  4. End Sub
  5.  
  6.  
  7. Private Sub Workbook_SheetActivate(ByVal Sh As Object)
  8.  
  9.     Application.EnableEvents = False
  10.     Application.ScreenUpdating = False
  11.  
  12.     If Sh.Index <> 1 And Sh.Name <> "system" And Sh.Name <> "runtime" Then
  13.  
  14.         ole_obj_img.inc_counter offset:=255
  15.  
  16.         'other code
  17.  
  18.     End If
  19.  
  20.     Application.ScreenUpdating = True
  21.     Application.EnableEvents = True
  22.  
  23. End Sub
  24.  
  25.  
What's killing the instances after inicialization ? If you know the solution provide some fix-code please too.

Any idea/solution what's wrong ?

TIA

Note: All test has been performed under Excel2k
Attached Files
File Type: zip ole_class_help.zip (36.4 KB, 59 views)
Aug 1 '07 #1
0 1231

Sign in to post your reply or Sign up for a free account.

Similar topics

10
9784
by: Fred | last post by:
There is a setting in INIT.ORA that has the unintended side-effect of making sure the ALTER SYSTEM KILL SESSION command has immediate affect. Without this setting, I've seen some instances where the session reports as being KILLED in V$SESSION but is not physically removed until the instance is bounced. Does anyone remember this value offhand?
15
2783
by: Mon | last post by:
I am in the process of reorganizing my code and came across and I came across a problem, as described in the subject line of this posting. I have many classes that have instances of other classes as member variables. So including a forward declaration doesnt help, does it? Faced with these, I had the following options: -Include the appropriate header in the header file that contains the class definition that has a member variable that is...
42
4999
by: WindAndWaves | last post by:
Dear All Can you tell me why you use a class module??? Thank you Nicolaas ---
9
2003
by: MLH | last post by:
I need a fundamental explanation of Class Modules - something suitable for newbies. Access 2.0 didn't seem to focus on them very much. Now that I'm using Access 97, it seems they're everywhere. thx N advance.
16
10993
by: A_PK | last post by:
Hi, I am a VB.net beginner, I do not know what are the major difference between Module vs Class. Could someone guide me when is the best situation to use Module or Class. I have no idea when should I use module or class, because no matter i use module or class, i always could get the results that are what i want. but just the declare and calling method is a bit different.
8
354
by: John | last post by:
We are looking to converting our old vb 6.0 apps to vb.net. In vb6 you could create a standard set of forms or modules that you could share with each application. As a result, lets say you opened up one application and changed something in a module shared throughout multiple apps. The next time you opened another app the changes would be there and you wouldn't have to reimport anything. However, this doesn't seem to be the case in...
19
4921
by: Jamey Shuemaker | last post by:
I'm in the process of expanding my knowledge and use of Class Modules. I've perused MSDN and this and other sites, and I'm pretty comfortable with my understanding of Class Modules with the exception of custom Collection Classes. Background: I'm developing an A2K .mdb to be deployed as an .mde at my current job-site. It has several custom controls which utilize custom classes to wrap built-in controls, and add additional functionality....
2
1468
by: mgoold2002 | last post by:
Hello. I've just begun programming in VB .NET, and I'm trying to turn all my modules into classes. In order to retrieve/exchange values from one class to another, I initiated New instances of the classes in each class where I needed to retrieve a property or method. I discovered that this reciprocal loading of class instances led to stackoverflow exceptions. I am now remedying this problem by sharing properties among the classes. I...
6
2248
by: Tim Hunter | last post by:
I am using Access 2003 under WinXP. I currently support a huge Excel Wokbook that is a maintenance nightmare. There are about 15 worksheets each with lots of formulas...Anyway I am thinking of converting this application to an Access solution and specifically using Class Objects. I am comfortable with Access but I have never worked with creating Classes. Finally my question. I am thinking of creating one Class Form Object to match one...
0
9655
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10172
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5535
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.