When I am running the below code for n number of document in a folder then it works fine but when i inclde more sub folder with the docs then it shows the error
"Run-time error '5792':
The files appears to be corrupted.
Can someone help? I am not much familier with coding.
Public Sub MassReplace()
.LookIn = "C:\Users\milans\Desktop\Procedure - Test" ' where to search
.SearchSubFolders = True ' search the subfolders
.FileName = "*.docx" ' file pattern to match
' if more than one match, execute the following code
If .Execute() > 0 Then
' for each file you find, run this loop
For i = 1 To .FoundFiles.Count
' open the file based on its index position
Documents.Open FileName:=.FoundFiles(i), ReadOnly:=False 'I tracked error it is the line where erorr is coming
' search and replace the address
.Text = "ABC"
.MatchCase = True
.Replacement.Text = "XYZ"
' save and close the current document
' if the system cannot find any files
' with the .doc extension
MsgBox "No files found."