I have multiple .doc files with the following structure:

[useless text #1]
[useful text]
[useless text #2]

Blocks of useless text are the same across files.

How do I batch-delete these useless blocks without corrupting formatting, pictures and hyperlinks in useful text?


4 Answers 4


You could try recording a VBA macro from your manual deletion actions, and then execute that macro (manually) in each document you need to process. Do you know how to record VBA macros in Word? If the text blocks always begin and end with the same text then that should be relatively easy, and save you some or most of the work.


Step 1: Press “Alt-F11” to open the Microsoft Visual Basic for Application window.

Step 2: Click Module on the Insert tab, copy and paste the following VBA code into the Module window.

Step 3: Then click Run (F5) button to apply the VBA.

VBA: searching and replacing same content across multiple documents at one time

Sub CommandButton1_Click()
Dim MyDialog As FileDialog, GetStr(1 To 100) As String '100 files is the maximum applying this code
On Error Resume Next
Set MyDialog = Application.FileDialog(msoFileDialogFilePicker) 
With MyDialog 
.Filters.Add "All WORD File ", "*.docx", 1 
.AllowMultiSelect = True
i = 1 
If .Show = -1 Then
For Each stiSelectedItem In .SelectedItems 
GetStr(i) = stiSelectedItem
i = i + 1 
i = i - 1 
End If 
Application.ScreenUpdating = False
For j = 1 To i Step 1
Set Doc = Documents.Open(FileName:=GetStr(j), Visible:=True)
With Selection.Find 
.Text = "search" 'Find What 
.Replacement.Text = "find" 'Replace With 
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Application.Run macroname:="NEWMACROS"
Application.ScreenUpdating = True
End With
MsgBox "operation end, please view", vbInformation
End Sub

Note: you can change the Text = "search”, Replacement.Text = "find” to specify the content to be searched and the content to be applied for replacement.

.Text = "search" 'Find What 
.Replacement.Text = "find" 'Replace With 

Credit: extendoffice


I had this issue all the time when I worked in civil engineering, needing to make multiple changes with large amounts of project documents at once - a program like this (or similar) fixed it for me;


Mine opened up all MS Word and Excel files in a directory and batch find/replaced many variables at once - this one looks like it can do Powerpoint too.


There is the online tool https://batch-edit.com that is free to use for exactly this use case. You can create a regex and replace the matched text in all doc files simultaneously with an empty text.

Full disclaimer: I am the author of the tool.

  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented May 7 at 19:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .