+ Reply to Thread
Results 1 to 4 of 4

Need a VBA code to run when a workbook is opened

  1. #1
    Registered User
    Join Date
    10-24-2012
    Location
    chino, ca
    MS-Off Ver
    Excel 2010
    Posts
    2

    Need a VBA code to run when a workbook is opened

    Hello, first time posting here. I have an Access query that overwrites an excel file everytime it is exported. I am wondering if I can have some VBA code in another workbook that when that Excel file, with the same name every time, is opened, the code will automatically run to open another workbook?

    Thanks.

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Need a VBA code to run when a workbook is opened

    YOu can set the name of the sub to Auto_Open and when the XL file opens it will automatically start that code....inside there you can do anything you want....the bad part --- when you need to troubleshoot the XL file auto-opens you have to hit Ctrl-Break to stop the code from running so you can fix/update/change your code....HTH
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Registered User
    Join Date
    10-24-2012
    Location
    chino, ca
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Need a VBA code to run when a workbook is opened

    I tried that, but when the file is overwritten, the code is lost. My thought is to store the code in a separate workbook so that when workbook A is opened (the overwritten file) workbook B will also open. But I'm not sure how to write that code or if it's even possible.

    Thanks.

  4. #4
    Registered User
    Join Date
    01-31-2014
    Location
    Chelmsford, England
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Need a VBA code to run when a workbook is opened

    I tried doing this by storing the Auto_Open macro in PERSONAL.XLSB, but :-(
    When I click on any existing file, the macro runs as soon as Excel opens but Before the worksheet opens ... which means that I get an error

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Use a macro to extract cell data from opened workbook to new opened workbook
    By BrianTFC in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-26-2014, 01:35 PM
  2. [SOLVED] Help with Code to reference workbook name based on file opened
    By thelegazy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-31-2013, 02:34 PM
  3. Change code to automatically SAVE when workbook is opened
    By debbiesh in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-05-2012, 03:21 PM
  4. Macro for inserting code into another workbook, to run when opened
    By hriggs in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-19-2009, 11:07 AM
  5. [SOLVED] Excel vba code disappears when saved workbook is re opened
    By Joshua Fandango in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-05-2005, 12:06 PM

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