Function PathExists(pname) As Boolean
' Возвращает ИСТИНА, если путь существует
Dim x As String
On Error Resume Next
x = GetAttr(pname) And 0
PathExists = (Err = 0)
End Function
Или:
Function PathExists3(path) As Boolean
' Возвращает ИСТИНА, если путь существует
Dim FSO As Object, FolderObj As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set FolderObj = FSO.getfolder(path)
PathExists3 = (Err = 0)
End Function
'Но я делаю по другому, без проверок:
Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long
Public Sub www()
Dim s$, a, st$
On Error GoTo www_Error
st = "k:"
s = ThisWorkbook.path: s = st & Mid(s, 3) & "\"
MakeSureDirectoryPathExists s
ThisWorkbook.SaveCopyAs (s & ThisWorkbook.Name)
Exit Sub
www_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure www"
End Sub
'В случае, если папки нет - она будет создана.