Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete an entire folders contents (or just Excel files)


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...o&userid=22629
View this thread: http://www.excelforum.com/showthread...hreadid=531060

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Delete an entire folders contents (or just Excel files)

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...o&userid=22629
View this thread: http://www.excelforum.com/showthread...hreadid=531060


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Delete an entire folders contents (or just Excel files)

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" wrote in message
...

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...o&userid=22629
View this thread: http://www.excelforum.com/showthread...hreadid=531060



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete an entire folders contents (or just Excel files)


Thank you both for the quick response. Both solutions appear to
accomplish the task I was looking for. Ron de Bruin - I thought it
might be easier than what I was putting into it, but I had no idea it
would be one line!! Thanks again.

DejaVu


--
DejaVu
------------------------------------------------------------------------
DejaVu's Profile: http://www.excelforum.com/member.php...o&userid=22629
View this thread: http://www.excelforum.com/showthread...hreadid=531060

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to open same name files in different folders in Excel? DrDisk7 Excel Discussion (Misc queries) 1 April 1st 08 02:35 PM
Password protect Excel and Word FOLDERS (not just files) Hedges Chandler Excel Discussion (Misc queries) 1 November 15th 05 07:23 PM
Moving files between folders using VBA in Excel Paul Excel Programming 2 August 5th 05 02:25 PM
Open Excel files/folders animalfriend7 Excel Discussion (Misc queries) 1 June 23rd 05 11:57 PM
delete all the contents (sub folders and files) in the temp folder Joseph Excel Discussion (Misc queries) 0 June 6th 05 08:01 AM


All times are GMT +1. The time now is 03:07 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"