+ Reply to Thread
Results 1 to 6 of 6

vba to check for folder and create it if it doesn't exist

  1. #1
    Forum Contributor
    Join Date
    08-04-2010
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    112

    vba to check for folder and create it if it doesn't exist

    I have a macro that creates three reports and saves them down to folder paths which have dated month folders in them

    Currently the save part of the macro looks like differing versions of this for all three of the file saves
    Please Login or Register  to view this content.
    Where the - " & Format(Date, "MMMYY") & "\ - portion is is the dated month folder part of the path the file needs to save down to. The issue is, on the first day of the month that folder wont exist. Now, it isn't that hard for the person running the macro to just go and add the folders themselves before they run, but if I could eliminate that step I would like to.

    Is anyone able to help with how I can go about making the macro check for the folder paths and create them if needed, but to progress as normal if they already exist?

  2. #2
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,176

    Re: vba to check for folder and create it if it doesn't exist

    I use the MakeSurePathExists API.

    E.G.
    Please Login or Register  to view this content.

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,531

    Re: vba to check for folder and create it if it doesn't exist

    This way directory gets created if not present before writing file to it.
    Please Login or Register  to view this content.
    Last edited by bakerman2; 05-30-2025 at 04:41 AM.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,176

    Re: vba to check for folder and create it if it doesn't exist

    In my experience MakeSurePathExists does create it if it doesn't exist already.

  5. #5
    Forum Contributor
    Join Date
    08-04-2010
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    112

    Re: vba to check for folder and create it if it doesn't exist

    Thanks both.
    That worked a charm. I had tried googling the answer and none of the answers I found made it as easy to understand as you both did.


    Thanks again

  6. #6
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,176

    Re: vba to check for folder and create it if it doesn't exist

    You're welcome.

+ 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. Create folder in list if it doesn't exist
    By ChrysanthiM in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 11-22-2016, 12:04 PM
  2. Create a Folder if it doesn't not exist.
    By Lucholac44 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-13-2016, 08:38 AM
  3. [SOLVED] VBA to save a workbook to a folder but create that folder if it doesn't already exist
    By cnixon in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-24-2014, 06:01 PM
  4. Code to create New Folder (if doesn't exist) and then Save Workbook to folder
    By jenhawley in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-10-2013, 03:09 PM
  5. Save a file to a folder, create folder if it doesn't exist
    By mcinnes01 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-01-2010, 09:12 AM
  6. Replies: 6
    Last Post: 08-11-2006, 03:41 PM
  7. Create Folder If It Doesn't Exist
    By Neutron1871 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-05-2005, 09: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