Path/File access error 75

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,404
Office Version
  1. 2016
Platform
  1. Windows
I am trying to move and rename the activeworkbook to another folder but I keep getting an Error 75 Path/File access error.

I'm using this:

VBA Code:
Dim sFolder As String
Dim dFolder As String

sFolder = ThisWorkbook.Path & "\"
dFolder = ThisWorkbook.Path & "\Update Folder\"

Name sFolder & ThisWorkbook.Name As dFolder & ThisWorkbook.Name

I have full read and write permissions on the drive in question, (which happens to be on a network), and the line which throws the error is:

VBA Code:
Name sFolder & ThisWorkbook.Name As dFolder & ThisWorkbook.Name

I have tried saving a copy of the current workbook by using this:

VBA Code:
Dim sFolder As String
Dim dFolder As String

sFolder = ThisWorkbook.Path & "\"
dFolder = ThisWorkbook.Path & "\Update Folder\"

ActiveWorkbook.SaveAs dFolder & "Test.xlsm"

and it works fine, the problem I then have is I get a permission denied error when I try to delete the original file, hence I thought the 'Name' procedure would be more efficient.

Is anyone able to offer me advice or an explanation as to why this won't work?
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Include all your code. Where do you try and delete the original file? Is it closed before you try and delete?
 
Upvote 0
What I've posted is all of my code with the exception of adding a Kill command to this, (if I try the 2nd piece of code where I try to use the Saveas):

VBA Code:
Dim sFolder As String
Dim dFolder As String
Dim OriginalFile As String

sFolder = ThisWorkbook.Path & "\"
dFolder = ThisWorkbook.Path & "\Update Folder\"
OriginalFile = ThisWorkbook.Path & "\" & ThisWorkbook.Name

ActiveWorkbook.SaveAs dFolder & "Test.xlsm"

Kill OriginalFile

Excuse my ignorance, but I thought the 'SaveAs' command effectively does close the original file, therefore leaving it ready to be deleted?
 
Upvote 0
Hello,

It gets awkward getting names and extensions correct. This code works. Let me know if there's any aspect that is unclear. I've commented where possible

VBA Code:
Sub SaveAsDelete()

    Dim sFullDestination As String
    Dim sNewName As String
    
    Dim sFileToKill As String
    
    'destination of new file
    sFullDestination = ThisWorkbook.Path & "\Update Folder\"
    
    'Name of new file
    
    sNewName = NameWithoutExtension(ThisWorkbook.Name) & "_TEST"
    
    'Remember this file's path and name
    sFileToKill = ThisWorkbook.FullName

    ThisWorkbook.SaveAs Filename:=sFullDestination & sNewName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
    
    Kill sFileToKill
End Sub

Private Function NameWithoutExtension(sName As String) As String
    Dim iPos As Integer
    
    'determine the position of the character immediately before the last period (name extension)
    iPos = InStrRev(sName, ".") - 1
    
    'Knowing the position of the file extension you can parse it out
    NameWithoutExtension = Left(sName, Len(sName) - (Len(sName) - iPos))
    
    
End Function
 
Upvote 0
Thanks gallen - I'll give that a try today and come back to you!
 
Upvote 0
gallen - I get 'sub/function not defined' on this line:

VBA Code:
sNewName = NameWithoutExtension(ThisWorkbook.Name) & "_TEST"

with this line highlighted:

VBA Code:
NameWithoutExtension

I've copied your code exactly with no changes.
 
Upvote 0
Ignore the last gallen - I'd put the function into a separate module then realised it was private so moved it to where your suggested routine is and it works fine.

Thank you!!
 
Upvote 0
Ok, what I thought was a problem solved has now thrown up some other errors.

I have used the following code but it randomly throws up an Error 70 Permission Denied in about 90% of cases:

VBA Code:
'destination of new file
sFullDestination = ThisWorkbook.Path & "\"

'Name of new file
sNewName = NameWithoutExtension(ThisWorkbook.Name) & "_TEMP"

'Remember this file's path and name
sFileToKill = ThisWorkbook.FullName

ThisWorkbook.SaveAs filename:=sFullDestination & sNewName, FileFormat:=xlOpenXMLWorkbookMacroEnabled

Kill sFileToKill

and it always fails on this line:

VBA Code:
Kill sFileToKill

I don't know if this is related, but if I put a break in the code before it gets to the Kill part and step through it, then it usually works without an error. So my thoughts are is it that somehow the original workbook is still being closed when it tries to kill? I have tried putting a 3-4 second pause after the .SaveAs part but this makes no difference.

I'm baffled....
 
Upvote 0
I'm baffled too. Tried it several times on my PC and it works fine. The location I'm saving to is a network location so that can't be an issue.


I've even called the sub from a separate sub where the code needs to return to after "Saving As" and still no issue.

:unsure::unsure:
 
Upvote 0

Forum statistics

Threads
1,215,353
Messages
6,124,458
Members
449,161
Latest member
NHOJ

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