'---------------------------------------------------------------------------------------
' Procedure : MakeDir
' DateTime : 2005-06-28 10:20
' Author : drawbrij
' Purpose : To make a Directory from within VBA. It checks if
' the Directory to be created already exists, and gives
' an Error message if so.
'
'Parameters:
'sDrive - the Drive on which the new directory is to be built
'sDir - the new directoryName
'
'Note: - Only creates 1 level per call
' - the sDir must have leading \ for each level of directory
' eg MakeDir "C" ,"\level1" <--call 1
' MakeDir "C" ,"\level1\level2" <--call 2
' will create c:\level1\level2 <--2 Calls required
'---------------------------------------------------------------------------------------
'
Sub MakeDir(sDrive As String, sDir As String)
On Error GoTo ErrorFound
VBA.FileSystem.MkDir sDrive & sDir
ErrorFound:
If Err.Number = 75 Then
MsgBox "Err 75 - Directory (" & sDrive & sDir & ") already exists"
ElseIf Err.Number = 0 Then
Exit Sub
Else
MsgBox Err.Number & " other error " & Err.Description
End If
End Sub
'---------------------------------------------------------------------------------------
' Procedure : RemoveDir
' DateTime : 2005-06-28 10:29
' Author : drawbrij
' Purpose : to remove a directory from within VBA.It checks if
' the Directory to be removed does not exist, and gives
' an Error message if so.
'
'Parameters:
'sDrive - the Drive from which the directory is to be removed
'sDir - the directoryName
'
'Note: - the sDir must have leading \ for each level of directory
' eg RemoveDir "C" ,"\level1\level2"
' will remove \level2
' and will leave C:\level1
'---------------------------------------------------------------------------------------
'
Sub RemoveDir(sDrive As String, sDir As String)
On Error GoTo ErrorFound
VBA.FileSystem.RmDir sDrive & sDir
ErrorFound:
If Err.Number = 76 Then
MsgBox "Err 76 - Directory (" & sDrive & sDir & ") doesn't exist"
ElseIf Err.Number = 0 Then
Exit Sub
Else
MsgBox Err.Number & " other error " & Err.Description
End If
End Sub
'---------------------------------------------------------------------------------------
' Procedure : testDirRoutines
' DateTime : 2005-08-04 15:28
' Author : drawbrij
' Purpose :to test the MakeDir and RemoveDir procedures.
' These were not used with OffLine Directory,
' but may have some usefulness
'---------------------------------------------------------------------------------------
'
Sub testDirRoutines()
RemoveDir "c", "\jack\newdir"
MakeDir "c", "\jack\newdir\nextDir"
MakeDir "c", "\jack\newdir\nextDir"
RemoveDir "c", "\jack\newdir\nextDir"
RemoveDir "c", "\jack\newdir"
End Sub