PDA

View Full Version : how to accept all changes in folders and subfolders



rachelboydjr
11-23-2018, 09:27 PM
I am trying to refresh my VBA Skills and our company has disabled many functions in Word 2016.

The code below works, but I can't get it to do subfolders as well, any suggestions are much appriciated in advance. Additionally, if you know how to easily addin 'deleteallcomment' that would be incredible.

Sub UpdateDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document, Rng As Range
strDocNm = ActiveDocument.FullName
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
If strFolder & "" & strFile <> strDocNm Then
Set wdDoc = Documents.Open(FileName:=strFolder & "" & strFile, AddToRecentFiles:=False, Visible:=False)
With wdDoc
For Each Rng In .StoryRanges
Rng.Revisions.AcceptAll
Next
.Close SaveChanges:=True
End With
End If
strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub

macropod
11-28-2018, 08:29 PM
Before your 'UpdateDocuments' sub, insert:

Dim FSO As Object, oFolder As Object, StrFolds As String

Sub Main()
Dim TopLevelFolder As String, TheFolders As Variant, aFolder As Variant, i As Long
TopLevelFolder = GetFolder
StrFolds = vbCr & TopLevelFolder
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 UpdateDocuments(CStr(Split(StrFolds, vbCr)(i)))
Next
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
Change your 'UpdateDocuments' sub's name from:
Sub UpdateDocuments()
to:
Sub UpdateDocuments(oFolder As String)
and change its line:
strInFolder = GetFolder
to:
strInFolder = oFolder

With the above changes, you now run the 'Main' sub.

rachelboydjr
11-29-2018, 07:19 PM
'Before your 'UpdateDocuments' sub, insert:"
This has saved me so much time!