Originally Posted by
mvidas
Brandon,
I made a function that checks if a directory exists, and if not then it creates it and returns the directory string as well. I'm not sure exactly how you're wanting to use it, but heres an example using your two cells:[vba]Sub brandonb8()
ActiveWorkbook.SaveAs CheckMakeUNCPath("J:\Asphalt Core Data\J6I1541\" & _
Range("B6").Text) & "filename.xls"
ActiveWorkbook.SaveAs CheckMakeUNCPath("J:\Asphalt Core Data\J6I1541\" & _
Range("B8").Text) & "filename.xls"
End Sub
Function CheckMakeUNCPath(ByVal vPath As String) As String
Dim PathSep As Long, oPS As Long
If Right(vPath, 1) <> "\" Then vPath = vPath & "\"
PathSep = InStr(3, vPath, "\") 'position of drive separator in path
If PathSep = 0 Then Exit Function 'invalid path
Do
oPS = PathSep
PathSep = InStr(oPS + 1, vPath, "\") 'position of directory
If PathSep = 0 Then Exit Do
If Len(Dir(Left(vPath, PathSep), vbDirectory)) = 0 Then Exit Do 'check path
Loop
Do Until PathSep = 0
MkDir Left(vPath, PathSep)
oPS = PathSep
PathSep = InStr(oPS + 1, vPath, "\")
Loop
CheckMakeUNCPath = vPath
End Function[/vba]Note that it will create all of the path that does not exist, like:[vba]Sub brandonb8_2()
MsgBox CheckMakeUNCPath("C:\Hi\Brandon\Welcome to\VBAExpress")
End Sub[/vba]Matt