Automatically run macro when opening file

Discussion in 'Microsoft Excel Programming' started by Chris, Dec 22, 2003.

  1. Chris

    Chris Guest

    Hello,
    I would like to run a macro automatically when the Excel file opens.
    The macro is written, but what do I do from here?

    Thank you,
    Chris
     
    Chris, Dec 22, 2003
    #1
    1. Advertisements

  2. Chris

    pikus Guest

    Open the Workbook.
    Press "Alt + F11"
    Press "Ctrl + R"
    There will be a window labeled Project - VBAProject
    Inside that window there will be listed any open workbooks.
    Look under the workbook you're working with to find "ThisWorkbook" an
    double-click it.
    Another window will appear with "ThisWorkbook (CODE)" in the titl
    bar.
    There will be two drop down menus near the top of this window.
    Drop both of these down and select "Workbook" from the one on the lef
    and "Open" from the one on the right.
    The body of the window should read:

    Private Sub Workbook_Open()

    End Sub

    Place the code there.

    - Piku

    --
    Message posted from http://www.ExcelForum.com
     
    pikus, Dec 22, 2003
    #2
    1. Advertisements

  3. Chris

    Kit Guest

    Add a SUB procedure titled Auto_Open to your module.
    execute your code in that SUB or call your routine as
    needed. The next time you open the spreadsheet your code
    will automatically run.

    Holding down the SHIFT key when opening the spreadsheet
    will suppress running the Auto_Open routine for testing.

    Sub Auto_Open()

    myRoutine

    End Sub

    Sub myRoutine()

    'Do your code here

    End Sub

    >-----Original Message-----
    >Hello,
    >I would like to run a macro automatically when the Excel

    file opens.
    >The macro is written, but what do I do from here?
    >
    >Thank you,
    >Chris
    >.
    >
     
    Kit, Dec 22, 2003
    #3
  4. Chris

    chris huber Guest

    Pikus-
    Thanks! That was the simplest task ever thanks to your detailed
    instruction. Much appreciated.



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    chris huber, Dec 22, 2003
    #4
  5. Chris

    Drlegend Guest

    name your macro
    auto_open
    see example below



    sub auto_open
    msgbox("Hello New User")
    end sub
     
    Drlegend, Dec 23, 2003
    #5
  6. Note that this method has been deprecated in favor of using the
    Workbook_Open event macro, placed in the ThisWorkbook module:

    Private Sub Workbook_Open()
    MsgBox "Hello New User" 'no parens needed
    End Sub

    One significant difference: Event macros will run if the workbook is
    opened from code. Automacros require an explicit RunAutoMacro
    statement.


    In article <013401c3c921$b1309240$>,
    "Drlegend" <> wrote:

    > name your macro
    > auto_open
    > see example below
    >
    >
    >
    > sub auto_open
    > msgbox("Hello New User")
    > end sub
    >
     
    J.E. McGimpsey, Dec 23, 2003
    #6
  7. Chris

    dhruvbhatt

    Joined:
    Aug 5, 2008
    Messages:
    1
    Likes Received:
    0
    PIKU >>I had the same question. I did the thing you said, but gives me compile error. It says Sub Expected. I am all new to vba excel project. Please help me out. Thanks.
     
    dhruvbhatt, Aug 5, 2008
    #7
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raphael Saddy

    Automatically run a macro when opening an Excel file

    Raphael Saddy, Jan 6, 2004, in forum: Microsoft Excel Programming
    Replies:
    10
    Views:
    992
    John Wilson
    Jan 15, 2004
  2. Darin Kramer

    Macro to run or not run a second Macro

    Darin Kramer, Dec 2, 2004, in forum: Microsoft Excel Programming
    Replies:
    2
    Views:
    367
    Frank Kabel
    Dec 2, 2004
  3. Ken Soenen

    run a macro automatically upon opening an XLS file???

    Ken Soenen, Dec 3, 2005, in forum: Microsoft Excel Programming
    Replies:
    2
    Views:
    296
    Ken Soenen
    Dec 4, 2005
  4. Tsp245
    Replies:
    2
    Views:
    450
    Tsp245
    Aug 14, 2008
  5. Munchkin

    Run macro automatically upon opening or closing document

    Munchkin, Jun 8, 2009, in forum: Microsoft Excel Programming
    Replies:
    1
    Views:
    310
    Jim Thomlinson
    Jun 8, 2009
Loading...

Share This Page