Results 1 to 10 of 10

Thread: AutoExec function in Excel???

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2000
    Location
    Switzerland
    Posts
    53
    Does it has in VBA for Excel the same function "AutoExec" and "AutoOpen" like these in VBA for Word?

    Thanks
    Scand

  2. #2
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    Worksheet, in Excel, has the following events:

    Activate
    BeforeDoubleClick
    BeforeRightClick
    Calculate
    Change
    Deactivate
    SelectionChange


    Putting code in the Activate event will "do stuff" when the worksheet is opened.

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2000
    Location
    Switzerland
    Posts
    53

    Thanks

    Thank you for your Help.

    For me VBA is a new language, so i don't have a big knowledge about it.

    Thanks
    Scand

  4. #4
    Lively Member
    Join Date
    Jun 1999
    Posts
    120
    As a matter of fact, yes, there is a sub
    (if present) that is automatically ran upon
    opening an Excel file (except of course
    if you disable macros)...

    it is the sub procedure Auto_Open()

    Code:
    Sub Auto_Open()
       msgbox "Welcome to my Excel file"   
    End Sub

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2000
    Location
    Switzerland
    Posts
    53

    That's exactly what i want.

    Thank you very much.

    That's exactly what i want.
    When the Auto_Open function exists, then i think the Auto_Close function should also exists.

    Thanks a lot
    Scand

  6. #6

    Thread Starter
    Member
    Join Date
    Mar 2000
    Location
    Switzerland
    Posts
    53

    Auto_Open

    Now with this function, it only works with my macro, when i open my macro, the code works, But i want, that the code works with evry file open in excel.

    How can i make, that the function Auto_Open is called by evry Workbook i'll open?


    Thanks
    Scand

  7. #7
    Lively Member
    Join Date
    Jun 1999
    Posts
    120
    This depends on the version of Excel you're using.

    *******************
    1) Excel 5
    a) Unhide your "Personal Macro Workbook"
    (Use Window->Unhide command)
    b) Write the sub Auto_Open()
    c) Hide the "Personal Macro Workbook"

    *******************
    2) Excel 1997 and up...there is still
    "help" on "Personal Macro Workbook" but
    I can't unhide it. Anyway, here's a
    crude way to go around this problem:
    just save the Excel file containing
    the sub Auto_Open() in the directory
    "..\Office\XlStart"

    NOTE: everytime you open an Excel file,
    this file (the one you saved) is also
    opened...sigh
    I have been trying to find a way other
    than the step above but to no avail...
    Please inform me if you have a solution
    other than this...
    *******************

    [Edited by KenX on 03-22-2000 at 05:47 AM]

  8. #8
    Lively Member
    Join Date
    Jun 1999
    Posts
    120
    If you are using Excel 97 up,
    make your sub procedure NOT in the
    "ThisWorkbook" but rather, on a new
    module (use Insert -> Module in the
    VB Editor)

  9. #9

    Thread Starter
    Member
    Join Date
    Mar 2000
    Location
    Switzerland
    Posts
    53

    Thanks for your fast answer

    My Macro is in the "Office\XlStart" path, the function "Auto_Open" is in a new module and i'm using Office 2000.
    But it wont work with the Auto_Open, the code in this function appears only when i open my macro, not when i open an other Excel file. Why this?
    I'm looking for an other solution, when i've found another one, i'll post it.

    Thanks
    Scand

  10. #10
    I've managed to get this working - if you're using excel 97+
    go to record macro, save in personal macro workbook, stop recording - edit the code and save. Every time you open excel it will perform the routine.
    If you want to perform this when you open a new workbook from within the app - try the following - create another macro in your personal macro book, it should look something like this:

    Workbooks.Add

    then add your code after the above statement ie:

    Workbooks.Add
    Range("a1").Activate
    ActiveCell.Value = "working"

    then customise the buttons and assign this macro to the 'new' button. that should do it!

Posting Permissions

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



Click Here to Expand Forum to Full Width