Word搜索指定位置的所有DOC文档 -电脑资料

电脑资料 时间:2019-01-01 我要投稿
【www.unjs.com - 电脑资料】

   

    本示例通过DIR来遍历指定文件夹中的所有WORD文档并且加上指定密码后保存并退出,

Word搜索指定位置的所有DOC文档

    Dim Adoc As String, PsDoc As Document

    On Error Resume Next

    ChDrive "C" ‘设置当前驱动器盘符

    ChDir "C:\Documents and Settings\My Documents\Temp" ‘进入指定目录

    Adoc = Dir("*.doc")

    Application.ScreenUpdating = False

    Do While Adoc <> "" ‘如果是文件夹,或者没有此文件,则会返回""

    ‘ MsgBox Adoc

    Set PsDoc = Documents.Open(Adoc) ‘打开指定文档

    PsDoc.Protect Type:=wdAllowOnlyFormFields, Password:="Password"

    PsDoc.Close True

    Adoc = Dir()

    Loop

    Application.ScreenUpdating = True

    使用的时候,请将如上的代码放在宏中来使用,

电脑资料

Word搜索指定位置的所有DOC文档》(https://www.unjs.com)。

最新文章