|
本帖最后由 batmanbbs 于 2023-6-2 20:38 编辑
- Sub 批量设置WORD文档密码()
- '
- ' 批量设置WORD文档密码(本代码放在EXCEL人员信息表中)
- ' 1.人员信息表确保A列为姓名(WORD文档名),B列为密码
- ' 2.WORD文档和EXCEL信息表在同一目录下
- '
- Dim arr() As Variant
- Dim Count%, FilePath$
- FilePath = ThisWorkbook.Path
- If Len(FilePath) = 0 Then MsgBox "本信息表未保存!": End
- With ThisWorkbook.Worksheets("Sheet1") ' 根据实际修改工作表名称:Sheet1
- Count = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("A2:B" & Count).Value ' 无标题行,A2修改成A1
- End With
- Dim wdApp, wdDoc As Object
- Dim FileName$
- Set wdApp = CreateObject("Word.application")
- For i = LBound(arr) To UBound(arr)
- If Len(Trim(arr(i, 1))) <> 0 Then
- FileName = FilePath & "\" & arr(i, 1) & ".docx" ' 修改成WORD文档的实际扩展名:doc/docx
- If Len(Dir(FileName)) = 0 Then
- MsgBox FileName & "不存在!"
- Else
- Set wdDoc = wdApp.Documents.Open(FileName)
- With wdDoc
- .ReadOnlyRecommended = False
- .Password = arr(i, 2)
- .Close True
- End With
- Set wdDoc = Nothing
- End If
- End If
- Next i
- wdApp.Quit
- Set wdApp = Nothing
- Erase arr
- End Sub
复制代码 |
评分
-
2
查看全部评分
-
|