我有名爲(「日期」)的工作表,我希望這個工作表被隱藏,只有通過密碼纔可見。 Application.ActiveSheet.Visible = False/True。Userform密碼取消隱藏工作表
我有一個用戶窗體設置。以下是我的表單背後的代碼。
Private passwordStatus As Boolean
Private Sub CommandButton1_Click()
Dim a As String
Dim Password As String
a = "123"
Password = TextBox1.Text
'Set Pawwordstatus at False before Testing
passwordStatus = False
If Password = a Then
MsgBox "Password Correct.", vbInformation
passwordStatus = True
Unload Me
Else
MsgBox "Password Incorrect. Please try again.", vbCritical
End If
End Sub
Function checkPassword() As Boolean
UserForm1.Show
'Shows the User Form. And after Closing the Form
'The PasswordStatus Value will be returned and you can check if
'it is true
checkPassword = passwordStatus
End Function
問題:我不知道我的背後工作表事件寫什麼代碼,用戶每次嘗試訪問該工作表的用戶窗體顯示和密碼請求訪問。
我背後的ThisWorkbook驗證碼:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Worksheets("Dates").Visible = False
'must save, if not save, it is not effect.
Me.Save
End Sub
非常感謝。我在本書中的LstSht.Activate中收到了「需要的對象」的錯誤。 – James
@詹姆斯 - 歐帕!我的錯。 'LstSht.Activate'應該是'LastActiveSht.Activate' – Mrig
再次感謝你一個了不起的工作 – James