+ Reply to Thread
Results 1 to 4 of 4

Check all files and subfolders for any tracked changes

Hybrid View

zak.horrocks Check all files and... 04-21-2021, 10:44 AM
macropod Re: Check all files and... 04-21-2021, 07:39 PM
zak.horrocks Re: Check all files and... 04-22-2021, 07:59 AM
macropod Re: Check all files and... 04-22-2021, 08:22 AM
  1. #1
    Forum Contributor
    Join Date
    09-09-2014
    Location
    England
    MS-Off Ver
    2013
    Posts
    102

    Check all files and subfolders for any tracked changes

    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

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,835

    Re: Check all files and subfolders for any tracked changes

    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]

  3. #3
    Forum Contributor
    Join Date
    09-09-2014
    Location
    England
    MS-Off Ver
    2013
    Posts
    102

    Re: Check all files and subfolders for any tracked changes

    You genius, this is perfect! Thank you so much.

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,835

    Re: Check all files and subfolders for any tracked changes

    You're welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] list of subfolders in folder - without files and sub-subfolders
    By MartyZ in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-11-2022, 10:56 AM
  2. VBA to check if any files in folder (and subfolders) are open?
    By Rerock in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-12-2014, 03:48 PM
  3. [SOLVED] Files within Multiple SubFolders and SubFolders Within It
    By codeslizer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-18-2013, 04:18 AM
  4. Excel Files that tracked link objects from other files
    By rookie_ck in forum Excel General
    Replies: 0
    Last Post: 05-10-2012, 09:01 PM
  5. A Way to Query,(x).Xls files in (x)subfolders
    By bdb1974 in forum Excel Programming / VBA / Macros
    Replies: 52
    Last Post: 08-06-2011, 04:17 AM
  6. [SOLVED] Open all files in subfolders
    By linglc in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-19-2006, 05:40 AM
  7. [SOLVED] copy subfolders, replace text in files and save files in copied subfolders
    By pieros in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-01-2005, 09:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1