Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Jun 2002
    Location
    vancouver, BC, Br. Columbia
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Fire NewWorkbook Event (Excel 2003)

    I know I've done this before, but for the life of me, I can't figure it out now! <img src=/S/blush.gif border=0 alt=blush width=15 height=15>

    I am building an Excel app as a template. I have a button in the template labelled "New File" which should create a new workbook based on the same template. When the new workbook is created, I want the NewWorkbook event to fire.

    I have created a new class called clsEvents with this code:

    Public WithEvents App As Application

    Private Sub App_NewWorkbook(ByVal Wb As Workbook)
    'this never fires
    MsgBox "new workbook event fired"
    End Sub

    The problem is that I don't know where to place the global variable to hold a pointer to my clsEvents.App object. Right now its in a module called Main:

    Dim AppObject As New clsEvents

    Sub Init()
    Set AppObject.App = Application
    End Sub

    .... but where should I call the Init() from?? Right now I'm calling it from ThisWorkBook.Workbook_Open.

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 15 Times in 15 Posts

    Re: Fire NewWorkbook Event (Excel 2003)

    Are you sure you that want the NewWorkbook event to fire? It it works, it would fire for EACH new workbook the user creates, unless you build in extra checks. Since you already have a command button that the user clicks to create a new workbook, you can call the code from there.
    And are you sure that you want to do all this in the template? A new workbook based on a template in Excel is a straight copy - all code from the template is copied into the workbook, so you'd end up with multiple instances of the event code. Perhaps an add-in or a workbook in XLSTART would be better.

  4. #3
    2 Star Lounger
    Join Date
    Jun 2002
    Location
    vancouver, BC, Br. Columbia
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Fire NewWorkbook Event (Excel 2003)

    Thanks Hans - I'll re-think how I'm doing this.

Posting Permissions

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