In order to replace the contents of many Word documents in a flash, we have to use the VBA method to achieve, the following is the methods, please see.
First, preliminary preparation
The following is a detailed procedure.
A, first place multiple Word documents that need to be bulk replaced under the same folder.
B, create a new blank Word document, right-click the blank toolbar, and click the Control Toolbox to see the Control Toolbox that is displayed on the screen.
C, on the Control Toolbox, click Command button, and a button is placed in the document.
D, double-click the button, enter the VB code writing mode, the following code to copy in.
The code of the command button
Private Sub CommandButton1_Click ()
application.screenupdating = False
Dim Mypas As String, MyPath as String, I as Integer, MyDoc as Document
With Application.filedialog (msoFileDialogFolderPicker)
. Title = "Select destination Folder"
If. Show =-1 Then
MyPath =. SelectedItems (1)
Else
Exit Sub
End If
End With
Mypas = InputBox ("Please enter Open password:")
With Application.FileSearch
. LookIn = MyPath
. FileType = msofiletypeworddocuments
If. Execute > 0 Then
For i = 1 to. FoundFiles.Count
Set MyDoc = Documents.Open (filename:=. FoundFiles (i), Passworddocument:=mypas)
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
. Text = "Officestudy"
. Replacement.text = "Www.dzwebs.com"
. 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
Mydoc.save
Mydoc.close
Set MyDoc = Nothing
Next
End If
End With
application.screenupdating = True
End Sub
Save the above code, exit VB edit mode, return to the Word document interface.
Click to select the button, and then click the First button in the Control Toolbox to exit design mode.
Finally, you can test: clicking the button again will reveal that "officestudy" in all Word documents underneath the folder is replaced with "www.dzwebs.com".
Note: In actual use, you can change the "" in the Above Code "" "in the quotation marks of the characters in the actual need to bulk replacement of the content. as shown below.
. Text = "Officestudy"
. Replacement.text = Www.dzwebs.net