gpt4 book ai didi

vba - Excel VBA : How to capture MsgBox response

转载 作者:行者123 更新时间:2023-12-03 01:42:27 26 4
gpt4 key购买 nike

我想执行以下任务:

  • 写下消息“你醒了吗?”并显示一个问号

  • 捕获整数变量 intR 中的响应,将 intR 值放入单元格 A2

  • 如果回答是"is",则在单元格 A1 中写入“Hurray”

  • 如果回答为“否”,则编写一个包含文本“ZZZZZZZZ”的消息框

  • 如果响应为“取消”,则退出子

    Sub EX3_1_6MsgBoxFunction()

    Dim intR As Integer
    Dim TxtRng As Range
    Dim stra As String
    Dim stra2 As String

    'Have the message box display the buttons Yes, No and Cancel


    intR = MsgBox("Are you awake ? ", vbQuestion + vbYesNoCancel)
    intR = Range("a2")

    If intR = vbYes Then
    Range("a1") = "Hurray"

    'that means yes

    ElseIf intR = vbNo Then
    stra2 = MsgBox("ZZZZZZZZZZ")

    Else

    Range("a2") = intR


    End If

    End Sub

最佳答案

你可以尝试这样的事情......

Sub EX3_1_6MsgBoxFunction()
Dim Ans As VbMsgBoxResult

'Have the message box display the buttons Yes, No and Cancel
Ans = MsgBox("Are you awake ? ", vbQuestion + vbYesNoCancel)

Select Case Ans
Case vbYes
Range("A1").Value = "Hurray"
Range("A2").Value = "Yes"
Case vbNo
Range("A1").Value = "ZZZZZZZZZZ"
Range("A2").Value = "No"
Case Else
Range("A1").Value = ""
Range("A2").Value = "Calcel"
End Select

End Sub

关于vba - Excel VBA : How to capture MsgBox response,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46231224/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com