To allow the user to pick files to process in a batch
Sub FilePicker()
'Opens a Dialog box, allows User to select multiple files
'to feed to Sub FindAndReplace_Brief for processing.
'
'For help, see: http://www.vbaexpress.com/forum/showthread.php?53869-Condensing-code
Dim FP As FileDialog
Dim FName As Variant
Set FP = Application.FileDialog( _
FileDialogType:=msoFileDialogFilePicker)
With FP
.AllowMultiSelect = True
If .Show = 0 Then Exit Sub
End With
For Each FName In FP.SelectedItems
FindAndReplace_Brief FName
Next FName
Set FP = Nothing
End Sub
You can make FindAndReplace_Brief shorter by use a "Find" Array and a Replacement" array
FindWhat = Array("XXX", "YYY", "ZZZ")
ReplaceWith = Array(tbox_CUTitle.Text, tbox_JO.Text, tbox_KO.Text)
For i = 0 To 2
With wrdApp.Selection.Find
.Text = FindWhat(i)
.Replacement.Text = ReplaceWith(i)
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
wrdApp.Selection.Find.Execute Replace:=wdReplaceAll
Next i