+ Reply to Thread
Results 1 to 6 of 6

Executing macro only once on open

  1. #1
    Registered User
    Join Date
    05-22-2018
    Location
    Bryn Mawr, Pennsylvania
    MS-Off Ver
    Excel 2013
    Posts
    12

    Executing macro only once on open

    hello
    I'm new to Excel Forum and a novas with Excel VB.
    I have a macro named AddSub which subtotals the rows of my file by company name. That macro works. What I want to do is have the macro run and the file save when the user opens the file for the first time - but only the first time. The macro does not need to execute each time the file is opened which is happening now. At the workbook level I have the open command and the macro below listed. AddSub is my subtotal macro which I want to run, then the file save. The next time the file is opened - nothing should happen. Thanks.

    Private Sub Workbook_Open()
    AddSub
    ActiveWorkbook.Save
    End Sub

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,483

    Re: Executing macro only once on open

    If the code is run the first time, would you be able to add today's date into a cell, then the next time the code is run, only run if that cell does not equal today's date.

  3. #3
    Registered User
    Join Date
    05-22-2018
    Location
    Bryn Mawr, Pennsylvania
    MS-Off Ver
    Excel 2013
    Posts
    12

    Re: Executing macro only once on open

    Hello,
    I don't want the code run again. Once the subtotal macro runs - it need not run again. It's just a subtotal.

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,483

    Re: Executing macro only once on open

    Yes, just run the code if today's date is not in the cell.......

  5. #5
    Registered User
    Join Date
    05-22-2018
    Location
    Bryn Mawr, Pennsylvania
    MS-Off Ver
    Excel 2013
    Posts
    12

    Re: Executing macro only once on open

    if the macro is run today and 5/22/2018 is in the cell, then the file opened tomorrow (5/23) will the macro run? Our Finance department will open the file and use it multiple times.

  6. #6
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,483

    Re: Executing macro only once on open

    If you want it only to run once, when the workbook is opened, it will check if the cell has today date in it, if not, then it will run the code, and place the date in the cell, so that next time the wb is opened, if first checks the date of the cell to see if it has to run the code or not.

+ 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. auto open macro not executing
    By wagner1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-21-2015, 02:55 PM
  2. [SOLVED] executing macro causes excel to open the workbook that the macro is associated with
    By YOO629 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-02-2015, 11:18 PM
  3. [SOLVED] Executing a SaveAs Command in an Open .txt File
    By HannahTee in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-18-2013, 10:57 PM
  4. Disable Workbook Open Event Until Other Code has finished Executing
    By dgdgdg in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-08-2013, 05:36 AM
  5. [SOLVED] Macro stops executing if another workbook is open
    By 4evra in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-01-2013, 12:32 PM
  6. When executing macro via hyperlink, macro doesn't re-scroll window back to A1
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-15-2011, 02:30 PM
  7. Open file after workbook executing code is closed
    By randell.graybill in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-13-2011, 10:05 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