Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
That works great! For me, just 2 lines of code is better. Just the Error
handler and the MkDir line. Thank you all for helping me immensely. -- I am running on Office 2003, unless otherwise stated. "Dave Peterson" wrote: I just ignore any error that may happen if the folder is already the Assuming that C:\my documents\excel exists: on error resume next mkdir "C:\my documents\excel\2010" mkdir "C:\my documents\excel\2010\January" on error goto 0 ====== Another option: Here's something that Jim Rech Posted: Option Explicit Declare Function MakePath Lib "imagehlp.dll" Alias _ "MakeSureDirectoryPathExists" (ByVal lpPath As String) As Long Sub Test() MakeDir "c:\aaa\bbb" End Sub Sub MakeDir(DirPath As String) If Right(DirPath, 1) < "\" Then DirPath = DirPath & "\" MakePath DirPath End Sub Orion Cochrane wrote: 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. -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
If A Directory Exists | Excel Programming | |||
File exists under directory | Excel Programming | |||
How to check if the directory exists? | Excel Programming | |||
Verify a directory exists | Excel Programming |