I want to create a folder at the address that is stored in the cell B6. The address is: H:\jpDesk\Desktop\Test Project
Sub SetUpLocalFolder()
Workbooks("Robot Model.xlsm").Activate
LocalPath = ActiveWorkbook.Worksheets("Preparation").Range("B6").Value
Debug.Print LocalPath
If Right(LocalPath, 1) <> "\" Then LocalPath = LocalPath & "\"
'check if the folder is already created
If Len(Dir(""" & LocalPath & """, vbDirectory)) = 0 Then
MkDir """ & LocalPath & """ 'Error shows here
MsgBox ("The local folder is successfully created.")
End If
End Sub
The error shows "runtime error '76'. Path not found" but Debug.Print shows the correct address. If I change the code into MkDir "H:\jpDesk\Desktop\Test Project", then everything works. Can someone please let me know why?
Scripting.FileSystemObjectinstead - it is much more robust than the ancient legacy file handling methods.