In an Excel macro, inside a loop I issue the following, where the names are unique each time:
Workbooks.Open Filename:=openFYL$ With Worksheets(1) ' .Copy ''do not need; saves BOOKn space .SaveAs svWK$ End With ' NOTE: Related metadata folders are created on the fly Open svWK$ For Input As #1 'EG: "USE_P001.TXT" When the loops are done, then and only then can i attempt to close and remove the files. Close 'MUST close files, for removal For PG = 1 To 7 '* Remove parsed secondary files for minimum handles For nsnFIND = 1 To 11 FPG$ = Right$("000" + Mid$(Str$(PG), 2), 3) REF$ = Right$("0" + Mid$(Str$(nsnFIND), 2), 2) svWK$ = "DET_R" + FPG$ + REF$ + ".txt" On Error Resume Next '** NOTE: does not always work Workbooks(svWK$).Close SaveChanges:=True Kill sav2$ RmDir deeFAULT$ + "DET_R" + FPG$ + REF$ + "_files" Next nsnFIND '* Remove parsed primary files for minimum handles FPG$ = Right$("000" + Mid$(Str$(PG), 2), 3) svWK$ = "DET_P" + FPG$ + ".txt" Workbooks(svWK$).Close SaveChanges:=True Kill svWK$ ' deeFAULT$ = "C:\Users\BOB\Documents\" ' PATH AND FILE NAME IS CORRECT ' Furthermore, the folder can manually be removed ' while program is running! dirLOC = deeFAULT$ + "DET_P" + FPG$ + "_files" On Error Resume Next ' to bypass access error RmDir dirLOC '** Path/File access error On Error GoTo 0 Next PG So,the folder specification in each case is absolutely correct, and as i indicate,i can manually delete/remove any one of them WHILE THE PROGRAM IS RUNNING (and creating more). How the heck can this be fixed? -- Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s =TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ https://www.facebook.com/discussexcel FORUM RULES 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Jobs posting is not allowed. 6) Sharing copyrighted material and their links is not allowed. NOTE : Don't ever post confidential data in a workbook. Forum owners and members are not responsible for any loss. --- You received this message because you are subscribed to the Google Groups "MS EXCEL AND VBA MACROS" group. To unsubscribe from this group and stop receiving emails from it, send an email to excel-macros+unsubscr...@googlegroups.com. To post to this group, send email to excel-macros@googlegroups.com. Visit this group at https://groups.google.com/group/excel-macros. For more options, visit https://groups.google.com/d/optout.