首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在excel中不断弹出输入框

问在excel中不断弹出输入框
EN

Stack Overflow用户
提问于 2021-07-29 03:15:01
回答 1查看 36关注 0票数 1

我正在尝试在VBA中键入代码,其中根据单元格值弹出一个宏按钮,并在单元格具有该特定值后键入密码。它在很大程度上是有效的,但在我输入密码后,输入框一直弹出。每当我点击另一个单元格或在不同的单元格中键入某些内容时,输入框在我输入admin的密码后不断弹出。我不确定它为什么会这么做。

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2021-07-29 03:43:27

Worksheet Change壮举。InputBox

代码语言:javascript
复制
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 Sub
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68566218

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档