Is there a way?

  • Thread starter Thread starter John Petty
  • Start date Start date
J

John Petty

Is there a way to create a directory using Excel VBA?

I am asking because I want to have an application search
for a directory in the users "My Documents" and if it
doesn't exist, create one for the user to save files to.

Thanks,

John Petty
 
This may give you an idea of how to go about it. This creates a backup in
any directory.

Sub Backup() 'kept in personal.xls & assigned to toolbar button
On Error GoTo BackupFile
MkDir CurDir & "\Backup"
BackupFile:
With ActiveWorkbook
MyWB = .Path & "\BACKUP\" & .Name
.SaveCopyAs MyWB
.Save
End With
End Sub
 
Ot may be worth taking a look at the Scripting Runtime DLL as this provides
the FileSystemObject that enables one to checke whether files/folder exist
etc

In the IDE, set a reference to MS Scripting Runtime and then take a look at
this code:

Sub CheckFolder()
Dim FSO As Scripting.FileSystemObject
Set FSO = New Scripting.FileSystemObject
Dim MyPath As String
MyPath = "C:\MyTempFolder"
If Not FSO.FolderExists(MyPath) Then
FSO.CreateFolder (MyPath)
End If
Set FSO = Nothing
End Sub

Its pretty simple. If you're folder is in fact a subfolder then you could
create in iteration to check if the parent folde exists too.
 
Back
Top