Consulting

Results 1 to 3 of 3

Thread: Solved: CHECK for folder and create it

  1. #1
    VBAX Regular
    Joined
    Sep 2005
    Posts
    78
    Location

    Solved: CHECK for folder and create it

    I want to do the following thing...

    Check if the folder ?RightAnswersTempWorkbooks? exists in the folder(take any).
    i. If the folder does not exist, create it.
    ii. If the folder exists, check for the existence of the folder ?RightAnswersTempWorkbooks<random number>? until a folder name is found that does not exist. Create the folder.

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Try this.
    [vba]
    Option Explicit

    Sub Macro1()

    Dim Num As Long
    Dim MaxNum As Long
    Dim MinNum As Long
    Dim Path As String

    MinNum = 1
    MaxNum = 1000
    Path = "C:\RightAnswersTempWorkbooks"
    On Error Resume Next
    MkDir Path
    Err.Clear
    Randomize
    Do
    Num = Int((MaxNum - MinNum + 1) * Rnd + MinNum)
    MkDir Path & "\RightAnswersTempWorkbooks" & Num
    If Err = 0 Then
    Exit Do
    Else
    Err.Clear
    End If
    Loop
    On Error Goto 0
    MsgBox "Folder Created: " & Path & "\RightAnswersTempWorkbooks" & Num

    End Sub
    [/vba]

  3. #3
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Very pretty, Jake!
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





Posting Permissions

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