VBA RmDir Method
Here is a simple method to delete the entire folder using VBA
Sub Delete_Folders_FS()
Dim sFolder As String
On Error GoTo Err_Msg
sFolder = "c:\temp\2Bdeleted\"
RmDir (sFolder)
Err_Msg:
If Err.Number <> 0 Then
MsgBox Err.Description
Err.Clear
End If
End Sub
Hi I tried with the code given for deleting a folder, but its showing error as Path/File access error. please tell me how to solve and also I need to delete only empty folder in a path, kindly help me providing suitable code.
ReplyDeleteThanks In advance
Because there are files in the folder you are trying to delete. Use the Kill statement to delete files then remove the folder...either that or use
ReplyDeleteobjFolder = "Path to folder"
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.deletefolder objFolder
Thanks, below is working fine.
ReplyDeleteobjFolder = "Path to folder"
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.deletefolder objFolder
Read more at http://vbadud.blogspot.com/2009/01/how-to-delete-folder-using-vba.html#OSEFl6CPmg3ih0dL.99