OaklandJim
Well-known Member
- Joined
- Nov 29, 2018
- Messages
- 855
- Office Version
- 365
- Platform
- Windows
I am trying to use some code that I got from a Mr Excel post. I need to create a folder that is six levels down. Keep getting that Runtime error 75, Path/File access error. Code I am using is here. Might someone assist with correction(s) needed?
and debug.print output is here.
FolderPath = C:\Users\Planner3\XXXXX\Order Book - General\Type1\
1. C:\
2. C:\Users\
3. C:\Users\Planner3\
4. C:\Users\Planner3\XXXXX\
5. C:\Users\Planner3\XXXXX\Order Book - General\
6. C:\Users\Planner3\XXXXX\Order Book - General\Type1\
VBA Code:
'routine to create your directory path
Sub MakeDirectory(FolderPath As String)
Debug.Print "FolderPath = " & FolderPath
Dim i As Integer
Dim strPath As String
Dim x As Variant
x = Split(FolderPath, "\")
For i = 0 To UBound(x) - 1
strPath = strPath & x(i) & "\"
Debug.Print i + 1 & ". " & strPath
'If Not FolderExists(strPath) Then MkDir strPath '<= Runtime error 75
Next i
End Sub
'function to check if folder exist
Function FolderExists(FolderPath As String) As Boolean
On Error Resume Next
ChDir FolderPath
If Err Then FolderExists = False Else FolderExists = True
End Function
and debug.print output is here.
FolderPath = C:\Users\Planner3\XXXXX\Order Book - General\Type1\
1. C:\
2. C:\Users\
3. C:\Users\Planner3\
4. C:\Users\Planner3\XXXXX\
5. C:\Users\Planner3\XXXXX\Order Book - General\
6. C:\Users\Planner3\XXXXX\Order Book - General\Type1\