Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 295
Default Movinf files to recycle bin

Hello, I want to achieve a few things with this code (below), but of course
it doesn't work. I did suspect it wouldn't be long before I posted a question!

If I take out the "If" and "For" it DOES delete the file, but I want it to
go to the Recycle Bin, and deleteFile seems to kill it completely.

Next, I want to loop through the client's folder and only delete certain
filenames (hence the if and For). When I have this part right I'll probably
wrap it in a Do loop to cycle through the various filenames. In the meantime
could some please help with the Recycle Bin, If and For part?

Regards, Brett

Sub aaDELETE_FILES_FROM_FOLDER()
surname = "surname"
initial = "I"
clientfolder = "C:\1. ACTIVE CLIENTS\" & surname & ", " & initial
clientfile = clientfolder & "\" & "2. NSC " & surname & ".xls"
Set fso = CreateObject("scripting.FileSystemObject")
For Each file In clientfolder.Files
If file.Path = clientfolder & "\" & "2. NSC " & surname & ".xls" Then
fso.deleteFile clientfile
On Error GoTo 0
End If
Next file

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 284
Default Movinf files to recycle bin

Here is a vbs file I wrote to send files to the recycle bin rather than
simply delete them. It's pretty easy to adapt to VBA

http://www.microsoft.com/technet/scr.../cscfi087.mspx


Steve Yandl



"Brettjg" wrote in message
...
Hello, I want to achieve a few things with this code (below), but of
course
it doesn't work. I did suspect it wouldn't be long before I posted a
question!

If I take out the "If" and "For" it DOES delete the file, but I want it to
go to the Recycle Bin, and deleteFile seems to kill it completely.

Next, I want to loop through the client's folder and only delete certain
filenames (hence the if and For). When I have this part right I'll
probably
wrap it in a Do loop to cycle through the various filenames. In the
meantime
could some please help with the Recycle Bin, If and For part?

Regards, Brett

Sub aaDELETE_FILES_FROM_FOLDER()
surname = "surname"
initial = "I"
clientfolder = "C:\1. ACTIVE CLIENTS\" & surname & ", " & initial
clientfile = clientfolder & "\" & "2. NSC " & surname & ".xls"
Set fso = CreateObject("scripting.FileSystemObject")
For Each file In clientfolder.Files
If file.Path = clientfolder & "\" & "2. NSC " & surname & ".xls" Then
fso.deleteFile clientfile
On Error GoTo 0
End If
Next file

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Movinf files to recycle bin

I'd start by using the code at Chip Pearson's site:
http://cpearson.com/excel/Recycle.htm



Brettjg wrote:

Hello, I want to achieve a few things with this code (below), but of course
it doesn't work. I did suspect it wouldn't be long before I posted a question!

If I take out the "If" and "For" it DOES delete the file, but I want it to
go to the Recycle Bin, and deleteFile seems to kill it completely.

Next, I want to loop through the client's folder and only delete certain
filenames (hence the if and For). When I have this part right I'll probably
wrap it in a Do loop to cycle through the various filenames. In the meantime
could some please help with the Recycle Bin, If and For part?

Regards, Brett

Sub aaDELETE_FILES_FROM_FOLDER()
surname = "surname"
initial = "I"
clientfolder = "C:\1. ACTIVE CLIENTS\" & surname & ", " & initial
clientfile = clientfolder & "\" & "2. NSC " & surname & ".xls"
Set fso = CreateObject("scripting.FileSystemObject")
For Each file In clientfolder.Files
If file.Path = clientfolder & "\" & "2. NSC " & surname & ".xls" Then
fso.deleteFile clientfile
On Error GoTo 0
End If
Next file

End Sub


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 295
Default Movinf files to recycle bin

Thankyou Steve, I'll have a play with it. Regards, Brett

"Steve Yandl" wrote:

Here is a vbs file I wrote to send files to the recycle bin rather than
simply delete them. It's pretty easy to adapt to VBA

http://www.microsoft.com/technet/scr.../cscfi087.mspx


Steve Yandl



"Brettjg" wrote in message
...
Hello, I want to achieve a few things with this code (below), but of
course
it doesn't work. I did suspect it wouldn't be long before I posted a
question!

If I take out the "If" and "For" it DOES delete the file, but I want it to
go to the Recycle Bin, and deleteFile seems to kill it completely.

Next, I want to loop through the client's folder and only delete certain
filenames (hence the if and For). When I have this part right I'll
probably
wrap it in a Do loop to cycle through the various filenames. In the
meantime
could some please help with the Recycle Bin, If and For part?

Regards, Brett

Sub aaDELETE_FILES_FROM_FOLDER()
surname = "surname"
initial = "I"
clientfolder = "C:\1. ACTIVE CLIENTS\" & surname & ", " & initial
clientfile = clientfolder & "\" & "2. NSC " & surname & ".xls"
Set fso = CreateObject("scripting.FileSystemObject")
For Each file In clientfolder.Files
If file.Path = clientfolder & "\" & "2. NSC " & surname & ".xls" Then
fso.deleteFile clientfile
On Error GoTo 0
End If
Next file

End Sub




  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 295
Default Movinf files to recycle bin

Thanks Dave, I'll check that too.

"Dave Peterson" wrote:

I'd start by using the code at Chip Pearson's site:
http://cpearson.com/excel/Recycle.htm



Brettjg wrote:

Hello, I want to achieve a few things with this code (below), but of course
it doesn't work. I did suspect it wouldn't be long before I posted a question!

If I take out the "If" and "For" it DOES delete the file, but I want it to
go to the Recycle Bin, and deleteFile seems to kill it completely.

Next, I want to loop through the client's folder and only delete certain
filenames (hence the if and For). When I have this part right I'll probably
wrap it in a Do loop to cycle through the various filenames. In the meantime
could some please help with the Recycle Bin, If and For part?

Regards, Brett

Sub aaDELETE_FILES_FROM_FOLDER()
surname = "surname"
initial = "I"
clientfolder = "C:\1. ACTIVE CLIENTS\" & surname & ", " & initial
clientfile = clientfolder & "\" & "2. NSC " & surname & ".xls"
Set fso = CreateObject("scripting.FileSystemObject")
For Each file In clientfolder.Files
If file.Path = clientfolder & "\" & "2. NSC " & surname & ".xls" Then
fso.deleteFile clientfile
On Error GoTo 0
End If
Next file

End Sub


--

Dave Peterson

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
retrieve items deleted from recycle bin Loser of important spreadsheet Excel Discussion (Misc queries) 1 August 28th 07 08:37 PM
Can I recover a file no longer in the Recycle Bin? Erlanger Excel Discussion (Misc queries) 2 November 22nd 06 05:43 PM
Recycle file replaced by mistak Tufail Excel Discussion (Misc queries) 1 October 12th 06 06:49 PM
recycle bin jelli Excel Discussion (Misc queries) 1 November 10th 05 07:50 PM
I accidentally replaced xcel file with another-not in recycle bin Sommerkal Excel Discussion (Misc queries) 2 August 15th 05 11:35 PM


All times are GMT +1. The time now is 04:50 AM.

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"