VBA code locks the folder and prevents deleting or renaming

kayteck

New Member
Joined
Sep 29, 2015
Messages
3
I have a following code (two sections):

1. - editing link to external file and updating date in the spreadsheet
Code:
FileToOpen = ToPath & "\Quotation\XXXX-XX-A_Client_Rev0.xlsm"
            Application.StatusBar = "Creating project folder. Please wait... - Updating files"
            Workbooks.Open Filename:=FileToOpen
            Workbooks("XXXX-XX-A_Client_Rev0.xlsm").Activate
            Worksheets("Measures").Activate
            ActiveWorkbook.ChangeLink Name:="C:\Project History.xlsx", NewName:=ToPath & "\Project History.xlsx", Type:=xlExcelLinks
            ActiveSheet.Range("Revision_date").Select
            ActiveCell.Value = Date
            ActiveWorkbook.Close SaveChanges:=True
            ThisWorkbook.Activate
and 2. - renaming the file
Code:
Application.StatusBar = "Creating project folder. Please wait... - Renaming files"
FromPath = ToPath & "\Quotation\XXXX-XX-A_Client_Rev0.xlsm" 
ToPath1 = ToPath & "\Quotation\" & Left(Project_number, 8) & "A" & Right(LabelProject, Len(LabelProject) - 9) & "_Rev0.xlsm" 
  Name FromPath As ToPath1


After running any of these, after the script is finished, I cannot rename or delete a folder "Quotation" with these files inside through Windows Explorer.
Files are being removed successfully, so just folder cannot be removed.

To rename or delete the folder I need to "Reset" (Stop) the script in VBA editor (even if it looks like successfully finished) or close Excel.

Is there any process to release the folder that have been used in the procedure or am I just missing something?

Please help.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,215,737
Messages
6,126,562
Members
449,318
Latest member
Son Raphon

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