Showing posts with label Create Directory in VBA. Show all posts
Showing posts with label Create Directory in VBA. Show all posts

Tuesday, November 8, 2016

Check Directory Exists If Not Create

Dim pathname As String, tripid As String, respCreate
Sub ChecknCreateDirectory()
tripid = "12"
pathname = "C:\Users\" & Environ("username") & "\Google Drive\" & tripid
   If (Len(Dir(pathname, vbDirectory)) = 0) Then
         rspCreate = MsgBox("Directory doesn't exist, do you wish to create it?", vbYesNo)
            If (rspCreate = vbYes) Then
                MkDir "C:\Users\" & Environ("username") & "\Google Drive\" & tripid
            End If
    End If
End Sub