Can't Delete Folder after creating it through VBA

Where in my code would I put that?

not sure if you’ve watched the full thread but I’m not trying to delete in VBA. I’m running VBA code to allow a user to create a folder and copy some files to it.

the problem occurs after that is complete as if the user then goes to delete the created folder/files through normal files manager they can’t.

if you press the reset button on the VBA editor you then can delete it despite it not showing any code is running.
 
actually, maybe not ... you need to RELEASE the object variables in your code. I see you've put some statements in, but commented them. That is why resetting works -- what it is doing is releasing your objects.
 
Last edited:
Oreynolds , close rs and release all objects after End With before Shell
 
The following procedure completely deletes the folder and its contents.

Code:
Sub ODeleteFolderAndFiles()
Dim FileSys, strDir As String
Set FileSys = CreateObject("Scripting.FileSystemObject")
strDir = "D:\Test" 'Specify the path to the folder here
If FileSys.FolderExists(strDir) Then
FileSys.DeleteFolder strDir
End If
End Sub
 
can you try, Application.FollowHyperlink instead of shell.

OK, tried:

Application.FollowHyperlink ("FoldernameDest")

But still won't allow you to delete folder until RESET button in VBA pressed!
 

Users who are viewing this thread

Back
Top Bottom