PDA

View Full Version : [SOLVED] Create Folder



Erays
04-12-2005, 01:38 PM
How would I code the a Macro to create a folder on the Environ desktop

Jacob Hilderbrand
04-12-2005, 01:46 PM
This Kb Entry (http://www.vbaexpress.com/kb/getarticle.php?kb_id=216) shows how to get the Desktop path.

Then just use MkDir to make the folder.

Zack Barresse
04-12-2005, 01:48 PM
Hi Erays,


A little something like this ...


Option Explicit

Sub MakeMyFolder()
Dim fSlash As String, dAddy As String
fSlash = Application.PathSeparator
dAddy = CreateObject("WScript.Shell").SpecialFolders("Desktop") & fSlash
'** Optional - will remove if it exists
On Error Resume Next
RmDir dAddy & "MyFolder"
On Error GoTo 0
MkDir dAddy & "MyFolder"
End Sub

.. quite similar to the old DOS commands .. :D

Jacob Hilderbrand
04-12-2005, 02:13 PM
That would delete the directory if it existed though so make sure that you want to do that.

You should probably just try to make the directory and see if there is an error. A slight modification of Zack's code will work.



Option Explicit

Sub MakeMyFolder()
Dim fSlash As String, dAddy As String
fSlash = Application.PathSeparator
dAddy = CreateObject("WScript.Shell").SpecialFolders("Desktop") & fSlash
On Error Resume Next
MkDir dAddy & "MyFolder"
If Err <> 0 Then
'The folder already exists
Else
'There was no folder so it was created
End If
On Error Goto 0
End Sub