Results 1 to 1 of 1

Run-time OleObject with events creating

Threaded View

  1. #1
    Registered User
    Join Date
    01-16-2007
    Location
    Near the box
    Posts
    58

    Run-time OleObject with events creating

    Hi there,

    I need some help with my project. I need to create some Ole objects with events in run-time.

    The proccess of creating the run-time object has to be associated with CommandButton click event.

    When I run the procedure from VB IDE, all works pretty fine until the button event associated with.

    But problem occured during calling procedure from Button event - only objects are created but NO
    events at all. What's wrong ? Any module (name) dependency or bad keyword (public, private) used
    somewhere ?


    Next I provide all parts of my project including List1; Modules : Module1,Module2; Class Modules : image_class_mod:

    Modules::Module1
    Public Sub create_images()
        
        ' run-time creating Ole object with event
        
        '========================================
        ' When running this procedure from IDE, all works pretty fine exactly what I need
        ' BUT when i assign this procedure to CommandButton only Images WITHOUT events are created
        '========================================
        
        ' Here is simplified skeleton how to create run-time Ole object with events
        
        Dim j As Integer
        Dim w As Worksheet
        Dim last_object As OLEObject
        
        Set w = Worksheets(1)
        
        For j = 1 To 3
            
            ' creat OLE image object
            w.Shapes.AddOLEObject _
            Left:=100 + j * 150, Top:=100, Width:=100, Height:=100, _
            ClassType:="Forms.Image.1"
            
            'reference to last created object
            Set last_object = w.OLEObjects(w.OLEObjects.Count)
            last_object.name = "image_" & CStr(j)
            
            'set event
            ReDim Preserve images_array(1 To j)
            Set images_array(j).image_class = last_object.Object
            
            Set last_object = Nothing
    
        Next j
        
        Set w = Nothing
        
    End Sub
    Modules::Module2
    Public images_array() As New image_class_mod
    Class modules :: image_class_mod
    Public WithEvents image_class As MSForms.Image
    
    Private Sub image_class_Click()
        
        MsgBox "Image click event raised"
    
    End Sub
    List1
    Private Sub CommandButton1_Click()
        
        ' Here I need to create IMAGES a EVENTS
        ' But it doesn't work as I expect
        ' only images are created
        
        create_images	' Damn ! This doesn't work as it should be - only OLE is created
        
        'I need events too ! What's wrong ?
            
    End Sub
    So the question is : how to correctly associate procedure for run-time object & event creating to CommandButton click event ?

    TIA
    Attached Files Attached Files
    Last edited by bettatronic; 07-01-2007 at 06:27 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1