vba word 批量删除批注

Sub 批量删除批注()

'

' 批量删除批注 Macro'

Dim fPk As FileDialog, fName, fType As String, 后缀 As String, t0, 计数

t0 = Timer

Set fPk = Application.FileDialog(msoFileDialogFilePicker)

With fPk

.AllowMultiSelect = True

.InitialFileName = "注意在此处放入需要处理word文件的文件夹地址"

.Show

fType = InputBox("请输入文件类型(支持通配符,如“doc*”):", "文件类型", "doc*")

If .SelectedItems.Count > 0 Then

For Each fName In .SelectedItems

If fType = "" Then

MsgBox "文件类型为空,将退出程序!", vbInformation, "出错提示"

Exit Sub

Else

后缀 = Right(fName, Len(fName) - InStrRev(fName, "."))

If 后缀 Like fType Then

Call 删除批注(fName)

计数 = 计数 + 1

End If

End If

Next

Else

MsgBox "您未选择文件,将退出程序!", vbInformation, "出错提示"

Exit Sub

End If

End With

Set fPk = Nothing

If 计数 > 0 Then

Debug.Print "完成,共处理了" & 计数 & "个文件。用时" & Timer - t0 & "秒。"

MsgBox "完成,共处理了" & 计数 & "个文件。用时" & Timer - t0 & "秒。"

Else

Debug.Print "完成,没有类型符合要求的文件。用时" & Timer - t0 & "秒。"

MsgBox "完成,没有类型符合要求的文件。用时" & Timer - t0 & "秒。"

End If

End Sub

Sub 删除批注(fName)

Dim aDoc As Document

Application.ScreenUpdating = False

Set aDoc = Documents.Open(fName)

'此处以下写对文件的具体处理过程

If aDoc.ProtectionType = 3 Then

aDoc.Unprotect Password:="3q"

End If

Selection.SetRange Start:=7497, End:=7497

aDoc.DeleteAllComments

Debug.Print "已完成对文件《" & aDoc.FullName & " 》的处理。 "

'此处以上写对文件的具体处理过程

aDoc.Close wdSaveChanges

Application.ScreenUpdating = True

Set aDoc = Nothing

End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值