View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ron de Bruin Ron de Bruin is offline
external usenet poster
 
Posts: 11,123
Default Making Directory if None Exists

You can start with this one

Change this line
FolderPath = "C:\Users\Ron\test3"

Sub Test_Folder_Exist_FSO_Early_binding()
'If you want to use the the Intellisense help showing you the properties
'and methods of the objects as you type you can use Early binding.
'Add a reference to "Microsoft Scripting Runtime" in the VBA editor
'(ToolsReferences) if you want that.

Dim FSO As Scripting.FileSystemObject
Dim FolderPath As String

Set FSO = New Scripting.FileSystemObject

FolderPath = "C:\Users\Ron\test3"

If Right(FolderPath, 1) < "\" Then
FolderPath = FolderPath & "\"
End If

If FSO.FolderExists(FolderPath) = False Then
FSO.CreateFolder FolderPath
Else
MsgBox "Folder exist"
End If

End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm




"Orion Cochrane" wrote in message
...
I need help making a directory if there isn't one present. I know you have to
use the mkdir command, but I don't know how to use it.

Here's an example:

I run a file, clear its contents, and save it. If I am clearing a December
file, I want a January file in a folder named 2010 in the current directory
and go up one folder (above the 2009 folder).

Basically, I need code to check whether a 2010 folder exists in a directory
path, and, if not, create it and save the file there.

TIA.
--
I am running on Office 2003, unless otherwise stated.