admin管理员组

文章数量:1592245

Excel文件夹加密可以使用VBA代码来实现,具体步骤如下:打开Excel文件,按“Alt+F11”打开VBA编辑器;

Excel文件夹加密可以使用VBA代码来实现,具体步骤如下:

1. 打开Excel文件,按“Alt+F11”打开VBA编辑器;

2. 在VBA编辑器中,打开“插入”菜单,选择“模块”;

3. 在模块窗口中,粘贴以下代码:

Public Function EncryptFolder(strFolderPath As String, strPassword As String)

Dim fso As Object

Set fso = CreateObject("Scripting.FileSystemObject")

Dim strParentFolder As String

strParentFolder = fso.GetParentFolderName(strFolderPath)

Dim objShell As Object

Set objShell = CreateObject("Shell.Application")

Dim objFolder As Object

Set objFolder = objShell.Namespace(strParentFolder)

Dim objFolderItem As Object

Set objFolderItem = objFolder.PName(fso.GetFileName(strFolderPath))

objFolderItem.InvokeVerbEx ("Encrypt")

objFolderItem.InvokeVerbEx ("Properties")

Dim objProperty As Object

Set objProperty = objFolderItem.GetDetailsOf(Nothing, 19)

Dim objWshShell As Object

Set objWshShell = CreateObject("WScript.Shell")

objWshShell.SendKeys strPassword & "{TAB}" & strPassword & "{ENTER}"

Set objProperty = Nothing

Set objFolderItem = Nothing

Set objFolder = Nothing

Set objShell = Nothing

Set fso = Nothing

End Function

4. 保存并关闭VBA编辑器;

5. 在Excel文件中,按“Alt+F8”打开宏管理器,选择上面刚刚添加的宏,点击“运行”;

6. 在弹出的对话框中,输入要加密的文件夹路径和密码,点击“确定”即可完成Excel文件夹加密。

本文标签: 示例文件夹加密代码Excel