+ Reply to Thread
Results 1 to 9 of 9

custom events

  1. #1
    Forum Contributor
    Join Date
    06-27-2006
    Posts
    310

    custom events

    I'm trying to get an understanding of custom events.

    There isn't much information by way of examples that I have been able to find on the internet.

    Could someone please provide a simple working example that I can use as a primer

    For example an event to be triggered anytime a public variable equals zero


    Thank you for your help.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Have a look at
    http://www.mrexcel.com/archive2/11900/13340.htm

    Along with the extensibility library, in excel (not the vbe), to Tools, Macro, security, Trusted Publishers and make sure the
    Trust Access to Visual Basic Project is selected.


    HTH

    rylo

  3. #3
    Forum Contributor
    Join Date
    06-27-2006
    Posts
    310
    Thanks but that seems to be showing how to add a sheet and write a procedure using code.

    Sub AddSheetWithEventCode()
    'For this procedure to work, you must add a reference to
    'Microsoft Visual Basic for Applications Extensibility

    'Declare variables
    Dim ws As Worksheet
    Dim cm As VBIDE.CodeModule
    Dim x As Long

    'Create a new worksheet in the active workbook
    Set ws = ActiveWorkbook.Worksheets.Add

    'Set a reference to the code module of the new sheet
    Set cm = ws.Parent.VBProject.VBComponents(ws.Name).CodeModule

    'Creat a new event procedure
    x = cm.CreateEventProc("Activate", "Worksheet")

    'Write code into the procedure
    cm.InsertLines x + 1, "MsgBox ""Hi there!"""
    cm.InsertLines x + 2, "MsgBox ""Hi again!"""
    cm.InsertLines x + 3, "MsgBox ""Hi three!"""

    'Release variables
    Set cm = Nothing
    Set ws = Nothing
    End Sub
    What I am looking for is an example of a custom event.

    A new event in excel.
    Last edited by SuitedAces; 09-15-2007 at 04:04 AM.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Forum Contributor
    Join Date
    06-27-2006
    Posts
    310
    Yeah I've already been there , he doesn't give an adequate example, at least not one that leaves me with a clear understanding

  6. #6
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    I went into google and put in the search

    "custom event" site:ozgrid.com

    It came up with a few responses. Didn't check, but if you give that a go, it may lead to something. I did the same search on mrexcel.com, but it didn't give too much.

    Let us know how it goes - you've got me interested.


    rylo

  7. #7
    Forum Contributor
    Join Date
    06-27-2006
    Posts
    310
    I see some good uses for it .

    I am not even certain at this point if custom events can be raised in the same way I am expecting.

    I have put a fair amount of time in searching the net for samples but have come up empty so far.

    Most of these sources you mention I have visited.

  8. #8
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Have you tried doing this using a class module? In google, search

    class module event site:mrexcel.com

    I fiddled with
    http://www.mrexcel.com/board2/viewtopic.php?t=89575
    (both bits of code) and wondered if you had tried / ignored / discounted this approach.

    Didn't look at too many others, but wondered if it would help....

    rylo

  9. #9
    Forum Contributor
    Join Date
    06-27-2006
    Posts
    310
    Yes I have used a class module and a WithEvents statement , which is for writing code against events that already exist in excel but don't have a module such as application level events.

    What I'm looking to find an example on is not the same.
    I am trying to get familiar with how to create a custom event based on the value of a variable without the need to associate it with any preexisting event.

    Such as my variable X goes to EMPTY and an event gets raised.

+ Reply to Thread

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