below macro does search and replace operations in nested subfolders.
The 'master folder' is hard coded on line 6. I wonder whether the macro can be tweaked to accommodate the following two requirements.
1. A folder picker is to let the user choose the 'master folder'
2. The built in Search and Replace Dialog is to appear where the user can enter his/her search and replace criteria.
Help is much appreciated.
Thank you very much in advance.
I wonder whether somebody could
Sub x_SearchAndReplace_MultipleFiles_Folders_Subfolders()Dim FSO As ObjectDim ROOT As ObjectDim fldr As Object Const strFolder = "C:\Trial\" Set FSO = CreateObject("scripting.filesystemobject") If Not FSO.folderexists(strFolder) Then MsgBox "Folder '" & strFolder & "' not found - Exiting routine", , "Error" Exit Sub End If Set ROOT = FSO.getfolder(strFolder & "\") processFolder ROOT.path For Each fldr In ROOT.subfolders processFolder fldr.path & "\" NextEnd SubSub processFolder(strFolder As String)Dim strFile As StringDim doc As DocumentDim rng As Word.RangeDim fileSet As Object strFile = Dir$(strFolder & "*.docx") Do Until strFile = "" Set doc = Documents.Open(strFolder & strFile) For Each rng In doc.StoryRanges With rng.Find .ClearFormatting .Replacement.ClearFormatting .Text = "15.500" .Replacement.Text = "19.500" .Replacement.Font.Size = 9 .Forward = True .Wrap = wdFindContinue .Execute Replace:=wdReplaceAll End With Next rng doc.Save doc.Close strFile = Dir$() LoopEnd Sub
thank you very much for your great and professional support.
looks awesome. It is a pity that line 100-105 does not work on my machine, but I am sure this has something to do that I run the macro on my business computer at my company.
Open in new window
I have to comment out all these lines, i.e. 100-105 for the macro to come up with the InputBoxes
The Input Boxes appear as desired, the strange thing is that whatever I enter as search and replace text, nothing is replaced. The files get opened and saved superfast, but no replacement action whatsoever. Any idea why?
Thank you and Regards, Andreas