不打开WORD文档批量替换文档内容


Sub 批量替换WORD内容()
Dim wd As New Word.Application
pa = ThisWorkbook.Path & "\111.docx"
With wd
.Documents.Open pa
.Visible = False
    For i = 2 To Cells(65535, 1).End(xlUp).Row
    .ActiveDocument.Content.Find.Execute findtext:=Cells(i, 1), replacewith:=Cells(i, 2), Replace:=wdReplaceAll, Forward:=True
    Next
.Documents.Save
.Quit
End With
Set wd = Nothing
End Sub

猜你喜欢

转载自www.cnblogs.com/lizicheng/p/9095502.html