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
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
(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
 
Upvote 0

Forum statistics

Threads
1,214,386
Messages
6,119,217
Members
448,876
Latest member
Solitario

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