PDA

View Full Version : Solved: Rename Folder - Error 75



pcsparky
03-11-2011, 02:55 PM
I keep getting error 75 which is Path/File access error if anyone is kind enough to spot what is going wrong for me please. I have checked that the old folder and new folder names are correct. :banghead:

Basically I'm changing filenames within the folder first using this code and after the Loop has finished trying to change the folder name:

myPath = ThisWorkbook.Path & "\Handlers\" & hName

ChDrive myPath

On Error GoTo changeFilename_error
ChDir myPath & "\"

fileName = Dir("*.xlsm")

Do While fileName <> ""

'CODE TO CHANGE FILE NAME AND OTHER STUFF

fileName = Dir()

Loop

newFolder = ThisWorkbook.Path & "\Handlers\" & tmp(1) & " " & tmp(2)

Name myPath as newFolder 'GET ERROR 75 HERE

shrivallabha
03-11-2011, 11:13 PM
I do not know the above syntax. However, following should work:
myPath = ThisWorkbook.Path & "\Handlers\" & tmp(1) & " " & tmp(2)


However, this may not work if the folder is not created so you can use following code to create desired folder:

Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CreateFolder (newFolder)

pcsparky
03-12-2011, 02:19 AM
Thanks. The folder does exist as it contains the files.

As I have already accessed the folder to change the file names, Excel is somehow not releasing the folder and assuming that it is in use, hence the error 75.

I have tried commenting out the file name change code and can get it to work, so need a way to get Excel to release its hold on this folder.

pcsparky
03-12-2011, 02:25 AM
OK sorted it.

Not sure which of these responsible but stuck them both in to make sure.

ChDrive path
ChDir path

Once Excel focused on another folder it worked fine.