Sub MakeDirIfNotExist(ByVal tgtpath$)
Dim dirpath$, tgtdrive$
Dim subpath As Variant
Dim i&
If InStr(tgtpath, ":\") = 0 Then
MsgBox "入力パスの形式が不正です"
Exit Sub
End If
If Right(tgtpath, 1) = "\" Then
tgtpath = Left(tgtpath, Len(tgtpath) - 1)
End If
tgtdrive = Left(tgtpath, 3)
subpath = Split(Mid(tgtpath, 4), "\")
dirpath = tgtdrive
For i = LBound(subpath) To UBound(subpath)
dirpath = dirpath & subpath(i) & "\"
If Dir(dirpath, vbDirectory) = "" Then
MkDir dirpath
End If
Next
End Sub