我正在尝试在VBA中键入代码,其中根据单元格值弹出一个宏按钮,并在单元格具有该特定值后键入密码。它在很大程度上是有效的,但在我输入密码后,输入框一直弹出。每当我点击另一个单元格或在不同的单元格中键入某些内容时,输入框在我输入admin的密码后不断弹出。我不确定它为什么会这么做。
Sub enable_()
Application.EnableEvents = True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
'If user is selected, hide button. If admin is selected, enter password to see the button'
If Range("A5") = "User" Then ActiveSheet.CommandButton1.Visible = False
If Range("A5") = "Admin" Then
strwork = InputBox("Please enter Admin Password.")
If strwork = "excel" Then ActiveSheet.CommandButton1.Visible = True
End If
End Sub发布于 2021-07-29 03:43:27
Worksheet Change壮举。InputBox
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
' If user is selected, hide button.
' If admin is selected, enter password to see the button'
Dim sCell As Range: Set sCell = Me.Range("A5")
If Intersect(Target, sCell) Is Nothing Then Exit Sub
With Me.CommandButton1
Select Case sCell.Value
Case "User"
If .Visible Then .Visible = False
Case "Admin"
Dim pWord As String
pWord = InputBox("Please enter Admin Password.")
'If .Visible Then .Visible = False
If pWord = "excel" Then
If Not .Visible Then .Visible = True
End If
End Select
End With
End Subhttps://stackoverflow.com/questions/68566218
复制相似问题