![]() |
#2
|
||||
|
||||
![]()
Try:
Code:
Option Explicit Dim FSO As Object, oFolder As Object, StrFolds As String Sub KillDocuments() Application.ScreenUpdating = False Dim TopLevelFolder As String Dim TheFolders As Variant, aFolder As Variant Dim strFile As String, i As Long TopLevelFolder = GetFolder StrFolds = vbCr & TopLevelFolder If TopLevelFolder = "" Then Exit Sub If FSO Is Nothing Then Set FSO = CreateObject("Scripting.FileSystemObject") End If 'Get the sub-folder structure Set TheFolders = FSO.GetFolder(TopLevelFolder).SubFolders For Each aFolder In TheFolders RecurseWriteFolderName (aFolder) Next 'Process the documents in each folder For i = 1 To UBound(Split(StrFolds, vbCr)) strFile = Dir(CStr(Split(StrFolds, vbCr)(i)) & "\*.doc", vbNormal) Do While strFile <> "" Kill CStr(Split(StrFolds, vbCr)(i)) & "\" & strFile strFile = Dir() Loop Next Application.ScreenUpdating = True End Sub Sub RecurseWriteFolderName(aFolder) Dim SubFolders As Variant, SubFolder As Variant Set SubFolders = FSO.GetFolder(aFolder).SubFolders StrFolds = StrFolds & vbCr & CStr(aFolder) On Error Resume Next For Each SubFolder In SubFolders RecurseWriteFolderName (SubFolder) Next End Sub Function GetFolder() As String Dim oFolder As Object GetFolder = "" Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0) If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path Set oFolder = Nothing End Function
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
delete document, loop folders |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
JingleBelle | Word VBA | 6 | 11-13-2020 07:36 AM |
Recent files not showing up unless they're in the default save directory | jderouen | Word | 0 | 05-12-2017 06:51 AM |
![]() |
PRA007 | Word VBA | 2 | 01-17-2016 09:04 PM |
Copy Files to a directory | elmnas | Word VBA | 8 | 07-11-2014 12:07 AM |
Weird problem - word docs are producing temp files that won't self delete | David92595 | Word | 0 | 07-07-2011 04:07 PM |