Tags: contents, delete, entire, excel, files, folder, folders, microsoft, msdn, software, vba

Delete an entire folders contents (or just Excel files)

On Microsoft » Microsoft Excel

3,932 words with 3 Comments; publish: Fri, 23 May 2008 03:15:00 GMT; (30662.50, « »)

Is it possible to delete the entire contents of a folder with the VBA?

I'd like to be able to delete either all of the files out of a folder

or delete all the Excel files out of a folder. I know I can use

Code:

--

Kill "C:\Test Folder\TestBk.xls"

--

I assume that I can use some sort of loop to find all the files in a

folder and delete them, but is it possible to Kill an entire folder's

contents?

TIA

DejaVu

--

DejaVu

---

DejaVu's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=22629

View this thread: http://www.excelforum.com/showthread.php?threadid=531060

All Comments

Leave a comment...

  • 3 Comments
    • Use the FileSearch Object.

      The following is from VBA help:

      With Application.FileSearch

      If .Execute() > 0 Then

      MsgBox "There were " & .FoundFiles.Count & _

      " file(s) found."

      For i = 1 To .FoundFiles.Count

      kill .FoundFiles(i)

      Next i

      Else

      MsgBox "There were no files found."

      End If

      End With

      "DejaVu" wrote:

      > Is it possible to delete the entire contents of a folder with the VBA?

      > I'd like to be able to delete either all of the files out of a folder

      > or delete all the Excel files out of a folder. I know I can use

      > Code:

      > --

      > Kill "C:\Test Folder\TestBk.xls"

      > --

      >

      > I assume that I can use some sort of loop to find all the files in a

      > folder and delete them, but is it possible to Kill an entire folder's

      > contents?

      > TIA

      > DejaVu

      >

      > --

      > DejaVu

      > ---

      > DejaVu's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=22629

      > View this thread: http://www.excelforum.com/showthread.php?threadid=531060

      >

      #1; Fri, 23 May 2008 03:17:00 GMT
    • You can use this to delete all the files in the folder

      Kill "C:\Test Folder\*.*"

      Or xls files

      Kill "C:\Test Folder\*.xls"

      --

      Regards Ron de Bruin

      http://www.rondebruin.nl

      "DejaVu" <DejaVu.25wt90_1144439102.5081.excel.todaysummary.com.excelforum-nospam.com> wrote in message

      news:DejaVu.25wt90_1144439102.5081.excel.todaysummary.com.excelforum-nospam.com...

      > Is it possible to delete the entire contents of a folder with the VBA?

      > I'd like to be able to delete either all of the files out of a folder

      > or delete all the Excel files out of a folder. I know I can use

      > Code:

      > --

      > Kill "C:\Test Folder\TestBk.xls"

      > --

      >

      > I assume that I can use some sort of loop to find all the files in a

      > folder and delete them, but is it possible to Kill an entire folder's

      > contents?

      > TIA

      > DejaVu

      >

      > --

      > DejaVu

      > ---

      > DejaVu's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=22629

      > View this thread: http://www.excelforum.com/showthread.php?threadid=531060

      >

      #2; Fri, 23 May 2008 03:18:00 GMT