Run-Time Error 75 "Path/File Access Error"

mrmacys

New Member
Joined
Jan 31, 2008
Messages
26
Hi All,

I'm encountering Run time error 75 on the below code. In the excel macro, when the file is not found the below codes run to save the excel workbook,

Dim a
a = MsgBox("Location not Found. Do you want to create this location?", vbCritical + vbYesNo, "Error")
If a = vbYes Then
MkDir "A:\KNITS\Season\" & Season & "\" & SeaYr & "\" & Category
MkDir "F:\KNITS\Season\" & Season & "\" & SeaYr & "\" & Category & "\" & Vndr
ActiveWorkbook.SaveAs "F:\KNITS\Season\" & Season & "\" & SeaYr & "\" & Category & "\" & Vndr & "\" & Fname & ".xls"

Else
End
End If


Fname refers to the excel file I'm saving,
 
MkDir will only create the lowest level folder and will fail if any of the parent folders are missing. You can use a function like this to build the whole thing as required:
Code:
Function CheckAndMakePath(strPath As String) As Boolean
   ' input must not include file name!
   Dim lngIndex
   On Error GoTo err_handle
   If right$(strPath, 1) <> Application.PathSeparator Then strPath = strPath & Application.PathSeparator
   CheckAndMakePath = True
   lngIndex = InStr(1, strPath, Application.PathSeparator, vbTextCompare)
   If lngIndex = 0 Then
      CheckAndMakePath = False
   Else
      Do
         If Dir(left$(strPath, lngIndex), vbDirectory) = "" Then MkDir left$(strPath, lngIndex)
         lngIndex = InStr(lngIndex + 1, strPath, Application.PathSeparator, vbTextCompare)
      Loop While lngIndex <> 0
   End If
   
leave:
   Exit Function
   
err_handle:
   CheckAndMakePath = False
   Resume leave
End Function
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Wow, i remember when ZIP drives where the best thing out. An any case,it was a typo above, I don't have an A drive, It should be F.
 
Upvote 0

Forum statistics

Threads
1,215,053
Messages
6,122,882
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top