View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
bigjim bigjim is offline
external usenet poster
 
Posts: 67
Default Making a directory if one doesn't exist

I am using excel 2003. The user enters a path name where he wants to save a
file. I need this code to check to see if the directory they enter exists
and if not I want to make the directory for them. This is the code I'm
using, but I get the error path not found when the program tries to save it.

Worksheets("ticket").Activate

strappend = ActiveSheet.Range("j8").Value
strpath = ActiveSheet.Range("b200").Value
str3 = ActiveSheet.Range("c8").Value



MsgBox strpath

Rem making directory if it doesn't exist
If Dir(strpath, vbDirectory) = "" Then MkDir strpath

fsavename = strpath & strappend & str3 & ".xls"

ThisWorkbook.SaveAs Filename:=fsavename

I am using the msgbox to make sure the path entered is getting assigned to
strpath and it is. J8 and C8 are the file name. In his case strpath =
c:\2008\Jun\ J8 = C005482 and C8 = Encana. I checked and the folder
c:\2008\jun\ was not created.

Any help would be appreciated.

Jim