I am trying to create a macro in order to do a mass find and replace across multiple word documents. I have found this one on the net and altered it to also apply for graphics however I keep getting a run time error (5174) saying that the file could not be found (even though it is definitely in the folder).
I believe the issue is this: support.microsoft.com/en-us/kb/212664 but am having a bit of trouble implementing it into my Macro as simply adding ".docx" after every single Fname doesn't seem to work.
I have limited experience with Macros so apologies if this is a novice question.
Any help would be greatly appreciated.
Sub ReplaceText() Dim Directory As String Dim FType As String Dim FName As String Directory = "C:\Users\pieria\Desktop\TempPics" FType = "*.docx" ChDir Directory FName = Dir(FType) ' for each file you find, run this loop Do While FName <> "" ' open the file Documents.Open FileName:=FName '<--Error is supposedly here ' search and replace the company name Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "CompanyA" .MatchCase = True .Replacement.Text = "CompanyB" End With Selection.Find.Execute Replace:=wdReplaceAll ' save and close the current document ActiveDocument.Close wdSaveChanges ' look for next matching file FName = Dir Loop End Sub