+ Reply to Thread
Results 1 to 2 of 2

Checking for subfolders and creating

  1. #1
    Gizmo63
    Guest

    Checking for subfolders and creating

    Hi all,

    I've seen this answered somewhere before but can't seem to find it now.

    I'm looking for some VBA coding to check is a subfolder exists on a preset
    path and create it if it doesn't.
    I have created code to get files and report errors if they're not there so I
    guess it'll be something along similar lines.
    The path to the level above the desired subfolder is a known variable e.g
    folderpath = "s:\merch\plandata\rangeplans"

    I need to check for existance of the next level:
    subfolderpath = "s:\merch\plandata\rangeplans\initials
    and create the subfolder if it isn't there.

    Thanks for your help.

    Giz

  2. #2
    Die_Another_Day
    Guest

    Re: Checking for subfolders and creating

    Here's something from Tom
    Function DirectoryExist(sstr As String)
    'Tom Oglivy
    Dim lngAttr As Long
    DirectoryExist = False
    If Dir(sstr, vbDirectory) <> "" Then
    lngAttr = GetAttr(sstr)
    If lngAttr And vbDirectory Then _
    DirectoryExist = True
    End If
    End Function

    Sub Test()
    Dim dirstr As String
    Dim wb As Workbook

    Set wb = ActiveWorkbook

    dirstr = "C:\MyDir"
    If Not DirectoryExist(dirstr) Then
    MkDir dirstr
    wb.SaveAs dirstr & "\ron.xls"
    Else
    wb.SaveAs dirstr & "\ron.xls"
    End If
    End Sub

    Charles

    Gizmo63 wrote:
    > Hi all,
    >
    > I've seen this answered somewhere before but can't seem to find it now.
    >
    > I'm looking for some VBA coding to check is a subfolder exists on a preset
    > path and create it if it doesn't.
    > I have created code to get files and report errors if they're not there so I
    > guess it'll be something along similar lines.
    > The path to the level above the desired subfolder is a known variable e.g
    > folderpath = "s:\merch\plandata\rangeplans"
    >
    > I need to check for existance of the next level:
    > subfolderpath = "s:\merch\plandata\rangeplans\initials
    > and create the subfolder if it isn't there.
    >
    > Thanks for your help.
    >
    > Giz



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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