1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| Sub MacroRunner()
Dim folderList() As String
Dim macroList() As String
Dim oFolderPath As String
Dim macroName As String
Dim i As Long, j As Long, k As Long
Dim oDoc As Document
Application.ScreenUpdating = False
ReDim folderList(0)
ReDim macroList(0)
Do
With Dialogs(wdDialogCopyFile)
If .Display <> 0 Then
oFolderPath = .Directory
folderList(UBound(folderList)) = oFolderPath
ReDim Preserve folderList(UBound(folderList) + 1)
Else
MsgBox "Cancelled by User"
Exit Sub
End If
End With
Loop While MsgBox("Do you want to process an additional folder?", vbYesNo + vbQuestion, _
"More Folders?") = vbYes
Do
macroName = InputBox("Enter the name of the macro that you want to run. CodeZapper, ToggleHideParaNos...", "Macro Name", "CodeZapper")
If Len(macroName) = 0 Then
MsgBox ("Nothing entered. Exiting routine.")
Exit Sub
Else
macroList(UBound(macroList)) = macroName
ReDim Preserve macroList(UBound(macroList) + 1)
End If
Loop While MsgBox("Do you want to run an additional macro?", vbYesNo + vbQuestion, _
"More macros?") = vbYes
For i = 0 To UBound(folderList) - 1
With Application.FileSearch
.NewSearch
.LookIn = folderList(i)
.SearchSubFolders = False
.FileType = msoFileTypeAllFiles
If Not .Execute() = 0 Then
For j = 1 To .FoundFiles.Count
Set oDoc = Documents.Open(.FoundFiles(j))
For k = 0 To UBound(macroList) - 1
Application.Run macroList(k)
Next k
ActiveDocument.Save
ActiveDocument.Close
Set oDoc = Nothing
Next j
Else
MsgBox "No files in specified folder(s)"
End If
End With
Next i
Application.ScreenUpdating = True
MsgBox "All Done"
End Sub |
Partager