Is there a way?

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
 
D

Don Guillett

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
 
P

Patrick Molloy

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top