Problems with FSO.MoveFolder / DeleteFolder. Can't delete

Gold_Ninja

New Member
Joined
Oct 22, 2012
Messages
21
I have a spreadsheet and some associated documents in a folder and I want to move them into another folder with a macro.

I quickly found out I could not use FSO.MoveFolder on the folder containing the excel sheet running the macro (It should have been obvious!).
So I opted to saveAs the excel sheet to a temporary folder, FSO.copyFolder everything to the new folder, saveAs the excel sheet into the new folder and delete the temporary sheet. I then FSO.deleteFolder the old folder (now empty) and everything should be fine.

Except: I cannot delete the folder which used to contain the spreadsheet running the macro. I get Error 70: Permission denied. The folder is empty but read-only and cannot be changed/deleted/opened while Excel is running.

Does anyone have any idea how I could release this folder from Excel's grasp?

I hope this makes sense, thanks in advance for any help offered and let me know if you need some more information.

Joel
 

Gold_Ninja

New Member
Joined
Oct 22, 2012
Messages
21
(I can't figure out how to edit my original post, sorry)

I have boiled this down to it's most basic while still replicating the problem. Here's my code:

Code:
Sub Button1_Click()

Dim FSO As Object
Dim fromPath As String
Dim toPath As String


fromPath = "C:\Contracts\Quotations\1234"
toPath = "C:\Contracts\Sales Orders\1234"


Set FSO = CreateObject("scripting.filesystemobject")


'Save a temporary copy to the C drive
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="C:\Estimation Backup.xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Application.DisplayAlerts = True


'Copy the Quotations folder and everything in it to the new Sales Orders folder
FSO.copyfolder Source:=fromPath, Destination:=toPath


'Delete the old folder from Quoatations (This where I get the problem)
FSO.deletefolder (fromPath)

End Sub
"C:\Contracts\Quotations\1234" is empty but I cannot delete it.

Thanks

Joel
 

Forum statistics

Threads
1,082,504
Messages
5,365,956
Members
400,863
Latest member
kimtid

Some videos you may like

This Week's Hot Topics

Top