+ Reply to Thread
Results 1 to 6 of 6

Macro to create new file each month

  1. #1
    Registered User
    Join Date
    01-06-2020
    Location
    USA
    MS-Off Ver
    2016
    Posts
    3

    Macro to create new file each month

    Every morning, I have a macro automatically run that updates a few history files. Each history file is large, so they must be split up by month. I'm spoiled by the Application.OnTime function everyday and don't want to have to make new history files each month. Is there a way to create new history files on the first of every month? The file would be basic, just the column headers and the "...Summary 2020-MM.xlsx" filename.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Macro to create new file each month

    Is your computer on 24/7? If not, and the first day of the month falls on a non-workday, then any automatic generation of a new file would be bypassed based on the date. But you could create a template and just open the template and do a saveas to create your new file.
    Last edited by JLGWhiz; 01-22-2020 at 05:40 PM.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Registered User
    Join Date
    01-06-2020
    Location
    USA
    MS-Off Ver
    2016
    Posts
    3

    Re: Macro to create new file each month

    I could leave the computer on 24/7, or at least keep it on around the new month. You did spark an idea. I could use Task Scheduler to open templates on the first of every month at a set time. Then use Application.OnTime function within these templates to save them with the new month in the filename and saved in the proper folders.

  4. #4
    Registered User
    Join Date
    01-04-2020
    Location
    Hull, UK
    MS-Off Ver
    2016
    Posts
    60

    Re: Macro to create new file each month

    This would check to see if the file exists based on the example ....Summary 2020-MM.xlsx in your chosen folder every time you open the file.

    Please Login or Register  to view this content.
    Because it's using today's date to create the filename, the first time it runs in a new month it will create the new file.

    For the rest of the month, once the file has been created it does nothing.

  5. #5
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Macro to create new file each month

    I think @juddaaaa has the best solution that does not require any exotic coding or special attention. Just a locgical check of the file name against the directory upon opening your workbook. It compensates for any weekends or holidays that might fall on the first of the month.
    Last edited by JLGWhiz; 01-22-2020 at 05:40 PM.

  6. #6
    Registered User
    Join Date
    01-06-2020
    Location
    USA
    MS-Off Ver
    2016
    Posts
    3

    Re: Macro to create new file each month

    JUDDAAAA! I love what you did. The template macro runs dormant if there's already a file with that name. I'll have to give it a shot tomorrow.

+ 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. Macro to create graph up to current month
    By danfullwood in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-30-2014, 04:12 AM
  2. How to create a 3 month reminder formula in an excel file?
    By thursday140 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 11-23-2013, 10:51 PM
  3. Macro to create new month from existing template
    By crosby87uk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-10-2012, 10:39 AM
  4. [SOLVED] Using Macro to separate a spreadsheet and create tabs for each month
    By ajang in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-26-2012, 01:42 AM
  5. macro save file for current year and month with a file name SHReportddmmyy.xls
    By evwang in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-14-2011, 10:38 PM
  6. Replies: 3
    Last Post: 09-30-2011, 04:35 AM
  7. [SOLVED] Macro to create files based on month/year
    By Jon in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-14-2005, 04:25 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