View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jacob Skaria Jacob Skaria is offline
external usenet poster
 
Posts: 8,520
Default creating a directory if one doesn't already exist

Modify as

If Dir(strpath, vbDirectory) = "" Then MkDir strpath

If this post helps click Yes
---------------
Jacob Skaria


"bigjim" wrote:

I am using excel 2003. In my workbook the user can enter the directory they
want to use for saving a file. They enter the path in cell B200. I want to
create the entered directory if it doesn't already exist. I am using this
code and it works if the directory doesn't exist, but if it already exists,
the program shuts down. I would appreciate any help. Strappend and str3
will be combined for the file name.

Dim strappend As String
Dim strpath As String
Dim str3 As String

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

If Dir(strpath) = "" Then MkDir strpath

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