+ Reply to Thread
Results 1 to 4 of 4

Run Macro when file is opened

  1. #1
    Registered User
    Join Date
    04-24-2018
    Location
    New Milford, NJ
    MS-Off Ver
    2013
    Posts
    11

    Run Macro when file is opened

    How do I get a macro to run whenever an Excel file is opened?

    Thank you,

    Gary

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Run Macro when file is opened

    Hi Gary,

    Welcome to the forum.

    To achieve that, place the following code on ThisWorkbook Module. To do that, press Alt+F11 to open VB Editor --> On the Project pane, double click ThisWorkbook and place the following code into the opened code window --> Save your workbook as Macro-Enabled Workbook.

    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Registered User
    Join Date
    04-24-2018
    Location
    New Milford, NJ
    MS-Off Ver
    2013
    Posts
    11

    Re: Run Macro when file is opened

    Thanks sktneer. It worked.

    Now I need a macro that executes when the workbook is closed. I tried replacing "open" with "close" in the macro above, but it didn't work.

    gary

  4. #4
    Registered User
    Join Date
    04-24-2018
    Location
    New Milford, NJ
    MS-Off Ver
    2013
    Posts
    11

    Re: Run Macro when file is opened

    My code generates a message box when the file is open. I don't know if this is possible, but I'd like to:

    1. Add three buttons to the message box
    2. button1: closes the message box
    3. button2: triggers a timer so the message box lingers for 5 minutes. At the end of that time, I either click button1 or, if I don't, a second message box pops up that more emphatically (can just be the text of the box, as in ! and CAPS) states that the task in hand has to get done
    4. button3: triggers a macro that shows a form with its own check boxes (each with text next to it). This form will only go away when all 4 or 5 checkboxes get checked)

    I attached an example I made in Word.

    Gary
    Attached Files Attached Files

+ 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. How to set a Global Macros so that it gets opened every time an excel file is opened?
    By pericopericone in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2013, 05:53 AM
  2. [SOLVED] Can't close file opened during a macro
    By simongilder in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 11-08-2012, 01:42 PM
  3. Splash screen in file opened by VBA hinders further processing of opened file.
    By Rod38 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-08-2012, 09:53 AM
  4. macro prompts immediately to open a file once the Excel file with the macro is opened
    By jhmayor03 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-03-2012, 10:00 AM
  5. [SOLVED] stop excel file opened as read only if already opened by another u
    By bobm in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-09-2011, 08:45 AM
  6. Run a macro only when file is opened via a batch file?
    By dylanemcgregor in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-28-2010, 12:17 PM
  7. macro to autofilter other file and copy in opened file
    By matthias in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-17-2006, 05:55 AM
  8. [SOLVED] Close file and run macro from newly opened file
    By Pradip Jain in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-23-2005, 07: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