How to delete a set of old word files by date or any other way
I have created many word files. I want to keep the files created in 2012 but delete all of the files before that. I can delete each single file but that will take too long. I want to delete a range of files at one time Can this be done by date or is
there another way? My email address is *** Email address is removed for privacy ***
Sub BatchProcessFiles()
'Note: You must add a reference Microsoft Scripting Runtime for this procedure to work.
'Use Tools>References to add the reference.
Dim strBatchDir As String
Dim oFSO As Scripting.FileSystemObject
Dim oBatchFolder As Scripting.Folder
Dim oBatchFile As Scripting.File
'Call function to pick a batch directory and set up for processing
strBatchDir = PickFolder
If strBatchDir = "Canx" Then Exit Sub
Set oFSO = New Scripting.FileSystemObject
Set oBatchFolder = oFSO.GetFolder(strBatchDir)
Application.ScreenUpdating = False
'Process files in the designated batch folder
For Each oBatchFile In oBatchFolder.Files
If Format(oBatchFile.DateCreated, "MM/DD/YYYY") < "1/1/2012" Then
Kill oBatchFile
End If
Next oBatchFile
Set oBatchFile = Nothing
Application.ScreenUpdating = True
lbl_Exit:
Exit Sub
End Sub
Function PickFolder() As String
'Open "Copy" so user can point and click to a path to use
Dim strFolderPath As String
With Dialogs(wdDialogCopyFile)
If .Display <> 0 Then
strFolderPath = .Directory
Else
MsgBox "Cancelled by User"
PickFolder = "Canx"
Exit Function
End If
End With
If Left(strFolderPath, 1) = Chr(34) Then
strFolderPath = Mid(strFolderPath, 2, Len(strFolderPath) - 2)
End If
If Right(strFolderPath, 1) = "\" Then
strFolderPath = Mid(strFolderPath, 1, Len(strFolderPath) - 1)
End If
PickFolder = strFolderPath
lbl_Exit:
Exit Function
End Function
Greg Maxey *** Death smiles at us all, but all a man can do is smile back.
For more help with Word visit: http://gregmaxey.com/word_tips.html
Was this reply helpful?
Sorry this didn't help.
Great! Thanks for your feedback.
How satisfied are you with this reply?
Thanks for your feedback, it helps us improve the site.