跳到主要内容

如何在Excel中一次保护文件夹中的所有工作簿?

在Excel中,您可以保护工作簿以防止其他用户对其进行编辑,但是您是否曾经想过一次保护多个工作簿? 在这里,我介绍了一些保护Excel中一个工作簿中的所有工作簿以及一个工作簿中的多个工作表的技巧。

使用VBA一次保护文件夹中的工作簿

使用 Kutools for Excel 一次保护多张工作表 好主意3

箭头蓝色右气泡 使用VBA一次保护文件夹中的工作簿

要保护特定文件夹中的工作簿,可以应用宏代码来解决。

1.启用一个新的工作簿,然后按 Alt + F11键 键打开 Microsoft Visual Basic应用程序ns窗口,然后单击 插页 > e,然后将以下代码粘贴到 模块 脚本。

VBA:保护文件夹中的工作簿。

Sub ProtectAll()
    Dim xWorkBooks As Workbook
    Dim xExitFile As String
    Dim xPassWord As Variant
    Dim xStrPath As String
    Dim xFileDialog As FileDialog
    Dim xFile As String
    On Error Resume Next
    Set xFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
    xFileDialog.AllowMultiSelect = False
    xFileDialog.Title = "Select a folder [Kutools for Excel]"
    If xFileDialog.Show = -1 Then
        xStrPath = xFileDialog.SelectedItems(1)
    End If
    If xStrPath = "" Then
        Exit Sub
    Else
        xStrPath = xStrPath + "\"
    End If
    xPassWord = Application.InputBox("Enter password", "Kutools for Excel", , , , , , 2)
    If (xPassWord = False) Or (xPassWord = "") Then
        MsgBox "Password cannot be blank!", vbInformation, "Kutools for Excel"
        Exit Sub
    End If
    xFile = "*.xls"
    xExitFile = Dir(xStrPath & xFile)
    On Error Resume Next
    Application.ScreenUpdating = False
    Do While xExitFile <> ""
        Set xWorkBooks = Workbooks.Open(xStrPath & xExitFile)
        Application.DisplayAlerts = False
        xWorkBooks.SaveAs Filename:=xWorkBooks.FullName, Password:=xPassWord
        Application.DisplayAlerts = True
        Workbooks(xExitFile).Close False
        Set xWorkBooks = Nothing
        xExitFile = Dir
    Loop
    Application.ScreenUpdating = True
    MsgBox "Successfully protect!", vbInformation, "Kutools for Excel"
End Sub

 

doc保护所有工作簿文件夹1

2。 按 F5 钥匙和一个 选择一个文件夹 弹出窗口,供您选择一个文件夹来保护其所有工作表。
doc保护所有工作簿文件夹2

3。 点击 OK 弹出对话框,输入保护工作簿的密码。
doc保护所有工作簿文件夹3

4。 点击 OK,将弹出一个对话框,提醒您所选文件夹中的所有工作簿已通过一个密码成功保护。
doc保护所有工作簿文件夹4

当您打开受以上代码保护的工作簿时,将弹出一个对话框,用于输入密码。 看截图:
doc保护所有工作簿文件夹5

Tips::此代码适用于2007或更高版本的Excel,如果您想将其应用于保护较低的版本,则可以更改 xFile =“ * .xls”xFile =“ * .xlsx” 在代码中。


箭头蓝色右气泡 使用 Kutools for Excel 一次保护多张工作表

实际上,在我们的日常工作中,保护工作簿中的多个工作表会更加频繁。 但是在Excel中,您需要使用其内置功能来一张一张地保护工作表。 但是,有一个强大的工具– Kutools for Excel,它的 保护工作表 实用程序可以帮助您一次保护工作簿的所有工作表或选定工作表。

Kutools for Excel, 与超过 120 方便的Excel功能,可提高工作效率并节省工作时间。

免费安装 Kutools for Excel,请执行以下操作:

1.启用要保护其工作表的工作簿,然后单击 企业 > 保护工作表。 看截图:
doc保护所有工作簿文件夹6

2.在 保护工作表 对话框中,您可以从列表中根据需要检查要保护的图纸。 看截图:
doc保护所有工作簿文件夹7

3。 点击 Ok,然后弹出另一个对话框供您输入和重新输入密码,请参见屏幕截图:
doc保护所有工作簿文件夹8

4。 点击 Ok,然后会弹出一个对话框,提醒您成功保护工作表。
doc保护所有工作簿文件夹9

要取消保护这些工作表,您只需点击 企业 > 取消保护工作表 输入用于取消保护的密码。
doc保护所有工作簿文件夹10

doc下载1

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (10)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I did all the steps and there was dialogue box saying it's successful but when I open the files, they are opening up without any password.
This comment was minimized by the moderator on the site
Hello, I have tried it here and it works. Please check whether the file extension in your code is correct?
This comment was minimized by the moderator on the site
am using a mac, and when i click on the F5 key it does not work for me, please how can I resolve it?
This comment was minimized by the moderator on the site
Hi, you can try option - F8 keys. But I only tested this VBA in Microsoft system, I do not know if it work in Mac.
This comment was minimized by the moderator on the site
Brilliant. Saves me nearly an hour every month. Thank you.
This comment was minimized by the moderator on the site
can you do the same code but for unprotecting? with option to browse for the folder
This comment was minimized by the moderator on the site
I'm getting a syntax error for the following: <span style="background-color...
This comment was minimized by the moderator on the site
Did you fix this ? How?
This comment was minimized by the moderator on the site
only remove them
This comment was minimized by the moderator on the site
workbook protect ...great program.... very helpful
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations