Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

excel vba

ResolvedVersion 2003

Frazer has attended:
Excel VBA Intro Intermediate course

Excel VBA

I have written a mcro to delete files from a shared drive. The macro selects files according to name criteria provided by the user but I also want to select by the file's last modified date. How can I do this ? Here is the code so far:

Sub Killer()
'macro to select & delete specific files
Dim Response As String
Dim datmod As Date
'Dim varNow As Variant 'the user form is shown & each button returns a different varNow value


Set fs = Application.FileSearch
With fs
.LookIn = InputBox("Enter the string for folder selection.", "Search folder criteria.", "S:\Operations\Analysts\text files")
Response = MsgBox("Search subfolders ?", vbYesNo + vbDefaultButton1 + vbQuestion, "Subfolders ?")
If Response = vbYes Then
.SearchSubFolders = True
Else
.SearchSubFolders = False
End If
'.LastModified <= InputBox("Include files last modified on or before date:", "Search folder criteria.", Date - 60)
.Filename = "*" & InputBox("Enter the string for file selection.", "Search criteria.") & "*" '"*0407.*"

If .Execute > 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."

ListDeleteOrCancel.Show
'##this is a user form with buttons to list the files (varnow =1), ##
'##delete them varnow = 2) or cancel (3)##

If varnow = 1 Then 'list files
Workbooks.Add
For i = 1 To .FoundFiles.Count
ActiveCell.Value = .FoundFiles(i)

ActiveCell.Offset(1, 0).Select
Next i
ElseIf varnow = 2 Then
For i = 1 To .FoundFiles.Count
Kill .FoundFiles(i)
Next i
MsgBox "There were " & .FoundFiles.Count & " files deleted."
Else
Unload ListDeleteOrCancel
Exit Sub
End If
Else
MsgBox "There were no files found."
End If
End With

End Sub

RE: Excel VBA

Hi Frazer

Thanks for your post and comprehensive detail, in these instances we can reach a solution for you but it is beyond the scope of the forum.

We would ask you to send us a copy of the files you are woring on with a guide list of areas to address. We will then get back to you with the scope of work and related costs, if you are happy to proceed we will then start work.

I shall email you direct so if you wish to progress this then please reply to me.

Kind regards

Jacob

Wed 3 Mar 2010: Automatically marked as resolved.

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Adjusting the Elevation and Rotation in a 3-D Chart

For any 3-D chart you create, you can adjust the chart

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.