ant批量处理word文件内容_word多个文件批量替换内容

Sub CommandButton1_Click()

Application.ScreenUpdating = False  '关闭屏幕闪

Dim myFile$, myPath$, i%, myDoc As Object, myAPP As Object, txt$, Re_txt$

Set myAPP = New Word.Application

With Application.FileDialog(msoFileDialogFolderPicker) '允许用户选择一个文件夹

.Title = "选择目标文件夹"

If .Show = -1 Then

myPath = .SelectedItems(1) '读取选择的文件路径

Else

Exit Sub

End If

End With

myPath = myPath & ""

myFile = Dir(myPath & "\*.docx")

txt = InputBox("需要替换的文字:")

Re_txt = InputBox("替换成:")

myAPP.Visible = True '是否显示打开文档

Do While myFile <> "" '文件不为空

Set myDoc = myAPP.Documents.Open(myPath & "\" & myFile)

If myDoc.ProtectionType = wdNoProtection Then '是否受保护

With myDoc.Content.Find

.Text = txt

.Replacement.Text = Re_txt

.Forward = True

.Wrap = 2

.Format = False

.MatchCase = False

.MatchWholeWord = False

.MatchByte = True

.MatchWildcards = False

.MatchSoundsLike = False

.MatchAllWordForms = False

.Execute Replace:=2

End With

End If

myDoc.Save

myDoc.Close

myFile = Dir

Loop

myAPP.Quit '关掉临时进程

Application.ScreenUpdating = True

MsgBox ("全部替换完毕!")

End Sub

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值