Consulting

Results 1 to 19 of 19

Thread: Check for folder; create if it does not exist

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Apr 2006
    Posts
    1
    Location

    Check for folder; create if it does not exist

    Hi everyone. I'm new to VBA and new to this site.

    I need to automate a few tasks in a file, then saveas to a folder. I need to see if the folder exists. If not, create the folder. I have a start. Could someone please let me know how to accomplish this? I'm not sure what matters here... I'm using VBA in Excel 2003 on an XP Pro system.

    The folder should be in the root of C: and be called 'P2P User Folder' or something similar.

    Sub Master()
     '
     ' Master Macro
     ' Macro recorded 4/20/2006 by CompuCat
     '
     ' Keyboard Shortcut: Ctrl+m
     '
     Application.DisplayAlerts = False
         Rows("1:1").Select
         Range("F1").Activate
         Selection.Delete Shift:=xlUp
         Columns("P:P").Select
         Selection.Delete Shift:=xlToLeft
     [This is where I need to see if the folder exists, and then create it, if it does not]
         ChDir "C:\P2P User Folder"
         ActiveWorkbook.SaveAs Filename:= _
             "C:\P2P User Folder\newuser.csv" _
             , FileFormat:=xlCSV, CreateBackup:=False
         ActiveWorkbook.SaveAs Filename:= _
             "C:\P2P User Folder\chguser.csv" _
             , FileFormat:=xlCSV, CreateBackup:=False
     End Sub
    Thanks, and I appreciate any advice you have.

    CompuCat
    Last edited by Aussiebear; 11-18-2018 at 07:24 PM. Reason: added correct tags to posted code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •