【发布时间】:2017-09-29 20:41:22
【问题描述】:
我正在编写一个代码,它会阻止用户保存工作簿,并且它只会在我想要的时候保存。这是为了防止用户在不应该进行更改和保存时进行更改。我已经创建了两个私人潜艇,但是当我自己保存工作簿时,我不知道如何例外。我希望能够将保存代码放在各种宏中,以便我可以随时控制保存。
以下是我的代码:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
MsgBox "You can't save this workbook!"
Cancel = True
End Sub
Private Sub Workbook_Open()
Dim myValue As String
Dim Answer As String
Dim MyNote As String
MsgBox "Welcome to the Lot Input Program"
If Range("A1").Value = "" Then
Line:
myValue = InputBox("Please input your email address:", "Input", "x@us.tel.com")
'Place your text here
MyNote = "Is this correct?: " & myValue
'Display MessageBox
Answer = MsgBox(MyNote, vbQuestion + vbYesNo, "Confirmation")
If Answer = vbNo Then
'Code for No button Press
GoTo Line
Else
Range("A1").Value = myValue
End If
ActiveWorkbook.Save
End If
End Sub
【问题讨论】:
-
您可以查看
Environ$("Username")来查看谁打开了它。这将返回他们用来登录计算机的用户名。