How To Apply A VBA Macro to All Subfolders in a Directory of a docx. Extension
Hi,
I am a novice VBA user.
I have about 300 files I need to process. I would like to apply a macro to all the files.
When the Files are in a standard folder I can use the macro below. It works perfectly.
It finds the files of a .docx type and applies a macro to it.
I now need help with a macro that will go through all the subfolders in the directory and apply my macro.
I have tested many versions of loop through directory VBA codes and have had no luck in getting the codes to work.
Sub ApplyMacroToAllFiles()
Dim file
Dim path As String
path = "C:\Users\\Desktop \Folder\"
file = Dir(path & "*.docx")
Do While file <> ""
Documents.Open FileName:=path & file
Call RemoveallBoldWords
ActiveDocument.Save
ActiveDocument.Close
' Set file to next in Dir
file = Dir()
Loop
End Sub
I simply need to be able to process the documents in the sub folders.
If any one can help me I would be so grateful. I have spent 2 days testing different VBA directory loop codes from the internet with no success.
I get run time errors, no response from the macro. It's really frustrating.
Thank you in advance
J
|