我的工作簿有以下公开活动:
Private Sub Workbook_Open()
ThisWorkbook.ChangeFileAccess xlReadOnly
End Sub
Run Code Online (Sandbox Code Playgroud)
然后这个按钮:
Sub UnlockDeveloper()
Dim pwd As String
pwd = InputBox("Enter developer password:", "Password")
If pwd = "password" Then
If ThisWorkbook.ReadOnly = True Then
ThisWorkbook.ChangeFileAccess xlReadWrite
End If
Else
MsgBox ("Incorrect password.")
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
这通常很好,但有时运行UnlockDeveloper子会导致VBAProject在VBA窗口中出现两次,我无法知道哪个是真实文件.如果我在错误的位置进行更改,则只要关闭Excel,更改就会丢失.

有人有任何想法如何防止这种情况?