VBA > Excel 檔要共用,但有幾個 Sheet 不給使用者輸入,有些欄位是要給其他人輸入,還有些要隱藏
----------------------------------------------------
Sub myProtectSharing()
'設定密碼
Dim myPWD As String
myPWD = "mypass"
'解除警告
Application.DisplayAlerts = False
'選擇Sheet2
With Worksheets("Sheet2")
.Select
'選擇要輸入的範圍並解除鎖定
Range("A1:B5").Select
Selection.Locked = False
Selection.FormulaHidden = False
'設定保護
.EnableOutlining = True
.Unprotect myPWD
.Protect Password:=myPWD, UserInterfaceOnly:=True
End With
'選擇Sheet3並隱藏
Worksheets("Sheet3").Visible = False
'將檔案共用保護後存檔
With ActiveWorkbook
'ThisWorkbook.SaveAs Filename:=ThisWorkbook.FullName, Accessmode:=xlShared
.ProtectSharing Password:=myPWD, SharingPassword:=myPWD
.SaveAs ActiveWorkbook.FullName
End With
Application.DisplayAlerts = True
End Sub
Sub myUnProtectSharing()
myPWD = InputBox("請輸入密碼!")
If myPWD <> "mypass" Then
MsgBox "Wrong password!"
Else
'解除所有保護與隱藏
Application.DisplayAlerts = False
ActiveWorkbook.UnProtectSharing SharingPassword:=myPWD
ActiveWorkbook.Unprotect myPWD
Worksheets("Sheet2").Unprotect Password:=myPWD
Application.DisplayAlerts = True
Worksheets("Sheet3").Visible = True
End If
End Sub
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言