VBA-Excel:从NOW每2分钟弹出一个有条件的消息框 [英] VBA-Excel : Conditional message box popup every 2 minutes from NOW

查看:304
本文介绍了VBA-Excel:从NOW每2分钟弹出一个有条件的消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力工作,现在(日期/时间),但一直没有成功。


  1. 如果Truebox在textbox1中捕获,Checkbox1。

  2. 从textbox1中的值,每2分钟,我需要一个弹出消息提醒,确定为确认,直到checkbox2为True。有人可以帮助这个逻辑和代码吗?谢谢。

      Dim X1 As Date 
    Dim X2 As Date
    Dim X3 As Date
    Dim X4 As Date

    Private Sub CheckBox1_Click()

    X1 = Now

    如果CheckBox1.Value = True则TextBox1.Value = Now

    调用function01

    如果CheckBox1.Value = False Then TextBox1.Value = Null

    End Sub

    Sub function01()
    X2 =00:02:00
    X3 = Now - X1
    X4 =格式(X3,hh:mm:ss)
    如果CheckBox1.Value = True然后

    如果X4 = X2然后
    MsgBox提示,vbOKOnlyTime Keeper工具提醒
    Else

    如果
    Else
    End If
    End Sub



解决方案

您可以使用 OnTime 事件而不是循环。



将代码更改为:

 如果CheckBox1.Value = True然后
TextBox1.Value = Now
schedulePopup
End If

和模块添加:

 公开Sub schedulePopup()
'// schedule popup
Application.OnTime Now + TimeValue(00:00:20),popupMessage,True
End Sub

public Sub popupMessage()
如果不是你的UserForm没有,那么
如果你的UserForm.CheckBox1.Value = True然后
MsgBoxTime Keeper工具提醒
'// schedule下一个
schedulePopup
End If
End If
End Sub


I have been trying to work things out with NOW (Date/time) but have been unsuccessful.

  1. Checkbox1 when True captures NOW in textbox1.
  2. From the value in textbox1, every 2 minutes i need a popup message reminder with OK as acknowledgement until checkbox2 is True. Can someone help with this logic and code? Thanks.

    Dim X1 As Date
    Dim X2 As Date
    Dim X3 As Date
    Dim X4 As Date
    
    Private Sub CheckBox1_Click()
    
    X1 = Now
    
    If CheckBox1.Value = True Then TextBox1.Value = Now
    
    Call function01
    
    If CheckBox1.Value = False Then TextBox1.Value = Null
    
    End Sub
    
    Sub function01()
    X2 = "00:02:00"
    X3 = Now - X1
    X4 = Format(X3, "hh:mm:ss")
        If CheckBox1.Value = True Then
    
             If X4 = X2 Then
              MsgBox "Prompt", vbOKOnly, "Time Keeper Tool Reminder"
             Else
    
             End If
        Else
        End If
    End Sub
    

解决方案

You can use the OnTime event rather than a loop.

Change your code to:

If CheckBox1.Value = True Then
    TextBox1.Value = Now
    schedulePopup
End If

And to a Module add:

Public Sub schedulePopup()
    '// schedule popup
    Application.OnTime Now + TimeValue("00:00:20"), "popupMessage", , True
End Sub

Public Sub popupMessage()
    If Not YourUserForm Is Nothing Then
        If YourUserForm.CheckBox1.Value = True Then
            MsgBox "Time Keeper Tool Reminder"
            '// schedule next
            schedulePopup
        End If
    End If
End Sub

这篇关于VBA-Excel:从NOW每2分钟弹出一个有条件的消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆