+ Reply to Thread
Results 1 to 3 of 3

Need to run a macro only when a new workbook opens

  1. #1
    Registered User
    Join Date
    11-06-2013
    Location
    Phoenix, az
    MS-Off Ver
    Excel 2013
    Posts
    26

    Need to run a macro only when a new workbook opens

    I need to find a way to have a macro execute ONLY if another workbook is opened. I export data from another source and it creates an Excel workbook. I would like a macro to trigger when it sees this workbook open (if that's possible). This macro would then go on to copy specific data from the workbook into the workbook I already have open (the workbook containing the macro). I need this to trigger multiple times. Only my workbook and the workbook that is opened from the data source would be open at any one time (so only 2 workbooks open at any given time). Once I've obtained the information I close the data source workbook and go back and do it all over again.

    I'm working in Excel 2013.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Need to run a macro only when a new workbook opens

    Hi

    If you put your macro in your Workbook Macro area

    And use the Deactivate event, then it will run each time the workbook loses focus.

    That includes if a new workbook is opened.


    Please Login or Register  to view this content.
    Open visual basic

    Select view project explorer

    click on "This Workbook"

    paste this code there.


    You will need to put some error checking in the macro to stop excel crashing.
    Last edited by mehmetcik; 05-04-2015 at 05:09 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    11-06-2013
    Location
    Phoenix, az
    MS-Off Ver
    Excel 2013
    Posts
    26

    Re: Need to run a macro only when a new workbook opens

    Brilliant! It never occurred to me to use the Deactivate to watch for another workbook opening!
    Works great.

    Thank you for your help.

+ 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. [SOLVED] Need a macro that opens another workbook but stays in current workbook
    By shoes1 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-28-2015, 08:44 PM
  2. how can i execute a macro in current workbook after another workbook opens?
    By sds1126 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-12-2014, 09:36 AM
  3. Replies: 3
    Last Post: 07-12-2014, 06:04 AM
  4. Replies: 1
    Last Post: 03-10-2014, 05:20 AM
  5. Macro that opens up another workbook
    By Chris_newton in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-01-2011, 01:54 PM

Tags for this Thread

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