跳到主要內容

如何在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

尖端:此代碼適用於2007或更高版本的Excel,如果您想將其應用於保護較低的版本,則可以更改 xFile =“ * .xls”xFile =“ * .xlsx” 在代碼中。


箭頭藍色右氣泡 使用Kutools for Excel一次保護多個工作表

實際上,在我們的日常工作中,保護工作簿中的多個工作表會更加頻繁。 但是在Excel中,您需要使用其內置功能來一張一張地保護工作表。 但是,有一個強大的工具– Excel的Kutools,其 保護工作表 實用程序可以幫助您一次保護工作簿的所有工作表或選定工作表。

Excel的Kutools, 與以上 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選項卡為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