Hi,
I want to create a Macro that will search through all files and subfolders in a directory, and then create a list of all files that have any tracked changes in them.
Is this possible and if so, any ideas on where to start?
Thanks
Z
Hi,
I want to create a Macro that will search through all files and subfolders in a directory, and then create a list of all files that have any tracked changes in them.
Is this possible and if so, any ideas on where to start?
Thanks
Z
For example:
![]()
Option Explicit Dim FSO As Object, oFolder As Object, StrFolds As String, TgtDoc As Document, StrDoc As String Sub DocRevisionsSummary() Application.ScreenUpdating = False Dim TopLevelFolder As String, TheFolders As Variant, aFolder As Variant, i As Long TopLevelFolder = GetFolder If TopLevelFolder = "" Then Exit Sub StrFolds = vbCr & TopLevelFolder Set TgtDoc = ThisDocument: StrDoc = TgtDoc.FullName 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)) Call CheckDocuments(CStr(Split(StrFolds, vbCr)(i))) 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 Sub CheckDocuments(oFolder As String) Dim strFldr As String, strFile As String, wdDoc As Document strFldr = oFolder If strFldr = "" Then Exit Sub strFile = Dir(strFldr & "\*.doc", vbNormal) Do While strFile <> "" If strFldr & "\" & strFile <> StrDoc Then Set wdDoc = Documents.Open(FileName:=strFldr & "\" & strFile, AddToRecentFiles:=False, ReadOnly:=False, Visible:=False) With wdDoc If .Revisions.Count > 0 Then TgtDoc.Range.InsertAfter vbCr & .FullName .Close False End With End If strFile = Dir() Loop Set wdDoc = Nothing End Sub
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
You genius, this is perfect! Thank you so much.
You're welcome.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks