Browse All Community Hubs. Turn on suggestions. Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type. Showing results for. Show only Search instead for. Did you mean:. Sign In. Occasional Contributor. Labels: Labels: Excel. Haytham Amairah. You can delete everything there except the files that are currently used by some applications.
But if we want to delete all the files in the folder, how can we delete it. Since we are using Excel VBA, can it delete other files? To do this, the first thing we need to do is we need to delete all the files in the folder by using the KILL function and then to delete the folder, and we need to use one more function called RmDir. Here RmDir will delete only the empty folder if any subfolder is where it cannot delete them. Below is the example code to delete the read-only files as well.
Here we discuss the VBA Code to delete 1. Particular File Name, 2. All files, 3. Entire folder, and 4. Read-only Files with downloadable excel template.
Below are some useful articles related to VBA —. Forgot Password? If they are, you'd have to add a flag for that.
Or unset the hidden attribute, similar to word. Close the doc file after saving it as a text file. Try releasing the Word object and seeing if that helps. Show 5 more comments. Active Oldest Votes. Try this: With CreateObject "Scripting.
Files If Left file. Roxton Roxton 7 7 bronze badges. Crownife Hmm. Have you made sure that the directory specified in the kill line ends with a backslash, as in my example? Also, are you running the kill in the For Each loop or from an array as suggested in the answer? I don't have Office on my machine at the moment but will be able to check on Monday. I'm running your code separately from mine to test it out. The backslash is included as well and the error 53 pops up. This shouldn't be related to ending the word process because its still the same after I restart the computer.
Error 53 is file not found which is odd because when I run a scan of the folder using a vba code, it does see the hidden files. Not sure why that should be I've tested it myself and it works , but I've updated the answer with another approach that might work.
0コメント