Hi am having mass replacing code but it is throwing error.. can any one help me in this regards ..
Run time error 5174
Is there any code for replacing a text containing morethan 250 Chars.... can anyone insert this into the below macro
Public Sub MassReplaceQ1()
Dim Directory As String
Dim FType As String
Dim FName As String
Directory = InputBox("PLEASE ENTER PATH", "SELECT THE TARGET FOLDER") & "\"
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
' search and replace the company name
Selection.find.ClearFormatting
Selection.find.Replacement.ClearFormatting
Selection.find.Replacement.Font.Name = "Angsana New"
Selection.find.Replacement.Font.Bold = True
Selection.find.Replacement.Font.Color = wdColorRed
With Selection.find
.Text = "preferred \\\stock / Inventory"
.MatchCase = True
.Replacement.Text = "preferred stock"
End With
Selection.find.Execute Replace:=wdReplaceAll
With Selection.find
.Text = "Cash received from return on investment income"
.Replacement.Text = "Cash received from investment income"
End With
Selection.find.Execute Replace:=wdReplaceAll
With Selection.find
.Text = "Reinsurance Accounts payable"
.Replacement.Text = "Reinsurance payable"
End With
Selection.find.Execute Replace:=wdReplaceAll
With Selection.find
.Text = "Of which:"
.Replacement.Text = "Including"
End With
Selection.find.Execute Replace:=wdReplaceAll
With Selection.find
.Text = "(1) "
.Replacement.Text = "(1)"
End With
Selection.find.Execute Replace:=wdReplaceAll
With Selection.find
.Text = "(2)"
.Replacement.Text = "(2)"
End With
Selection.find.Execute Replace:=wdReplaceAll
With Selection.find
.Text = "common \\\stock / Inventory"
.Replacement.Text = "common stock"
End With
Selection.find.Execute Replace:=wdReplaceAll
With Selection.find
.Text = ""
.Replacement.Text = ""
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