VBA Delete File from Computer Folder
There should be multiple ways to do it. In this article, I have given 2 methods.
One is by using Filesystemobject & other uses VBA.Kill function.
Parameter for both is the same. The file File path or wildcard.
Here is the sample VBA code to Delete a file:VBA Delete File from FolderVisual Basic123456789101112Sub VBA_Delete_File()Dim fso As Object, filePath As StringSet fso = Create.Object("Scripting.Filesystemobject")filePath = "D:\SomeFilename.txt"fso.deletefile (filePath) 'ORVBA.Kill (filePath)MsgBox "Files Deleted"End Sub
Permission Denied while Delete File Operation
This is a common error that occurs many times. To this, follow these options.
- Check if the file exists.
- Check that the folder you are processing does not have spaces in its name. Yes. It is crazy. If the folder name is like “Folder For Processing”. The above functions does not work. The folder name has to be changed to “Folder_For_Processing” or “FolderForProcessing”.
Once you check both the above options the functions will work just fine. It is probably a bug at the older version of Windows systems. But, still you can take a work around and use any Command Prompt batch file to delete files in these cases.
VBA to Delete File in a Folder
- Block Apps in FaceBook print screen Excel Countif Record Macro Timer in Excel Task Manager VCF HTML Table Import Data Thumbnails Text to Speech TTS Candy Crush C++ Programing Machine learning AI bulk email Excel VBA vba color index vba color codes Android social media Twitter Google+ Google Adsense Tips bitcoin Calendar in Excel outlook vba mass email Data Mining Excel Macro Facebook WhatsApp python Wordpress