會儲存活頁簿並將它設為共用保護。
語法
表達。ProtectSharing (FileName、Password、WriteResPassword、ReadOnlyRecommended、CreateBackup、SharingPassword、FileFormat)
詞 代表 Workbook 物件的變數。
參數
| 名稱 | 必要/選用 | 資料類型 | 描述 |
|---|---|---|---|
| FileName | 選用 | Variant | 會指出已儲存的檔案之名稱字串。 您可以在檔案名稱中加入完整路徑;如果不加入路徑,則 Microsoft Excel 會將該檔案儲存到目前資料夾。 |
| Password | 選用 | Variant | 有區分大小寫的字串,指出要指定給檔案的保護密碼。 長度不超過 15 個字元。 |
| WriteResPassword | 選用 | Variant | 會指出此檔案的寫入保護密碼的字串。 如果檔案是使用密碼儲存,且開啟檔案時未提供密碼,則檔案會以唯讀方式開啟。 |
| ReadOnlyRecommended | 選用 | Variant | True,在開啟檔案時會顯示一個建議以唯讀模式開啟檔案的訊息。 |
| CreateBackup | 選用 | Variant | 如果為 True ,則會建立備份檔案。 |
| 共用密碼 | 選用 | Variant | 會指出用於檔案共用的保護密碼之字串。 |
| FileFormat | 選用 | Variant | 會指出檔案格式的字串。 |
註解
Use strong passwords that combine uppercase and lowercase letters, numbers, and symbols. Weak passwords don't mix these elements.
- 強密碼:Y6dh!et5
- 弱密碼:House27
Passwords should be 8 or more characters in length. A pass phrase that uses 14 or more characters is better. 記住密碼至關重要。 If you forget your password, Microsoft cannot retrieve it. Store the passwords that you write down in a secure place away from the information that they help protect.
範例
本範例會儲存第一個活頁簿並將它設為共用保護。
Sub ProtectWorkbook()
Dim wbAWB As Workbook
Dim strPwd As String
Dim strSharePwd As String
Set wbAWB = Application.ActiveWorkbook
strPwd = InputBox("Enter password for the file")
strSharePwd = InputBox("Enter password for sharing")
wbAWB.ProtectSharing Password:=strPwd, _
SharingPassword:=strSharePwd
End Sub
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。