1

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?

0

4 Answers 4

1

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.

0

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.Clear 
.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 
Next
i = i - 1 
End If 
Application.ScreenUpdating = False
For j = 1 To i Step 1
Set Doc = Documents.Open(FileName:=GetStr(j), Visible:=True)
Windows(GetStr(j)).Activate
Selection.Find.ClearFormatting 
Selection.Find.Replacement.ClearFormatting
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"
ActiveDocument.Save
ActiveWindow.Close
Next
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

0

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;

https://www.etsy.com/listing/1468077519/smart-replace-pro-automated-find-replace

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.

0

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.

1
  • 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 .