VBA:如果VBA主用户表单在后台运行,消息用户表单将弹出并在所有应用程序前保持活跃



我创建了一个VBA代码,其中消息用户表单在采取某种行动后弹出。问题是,当VBA主用户表单在后台运行时(在另一个活动的应用程序后面),消息userform弹出,但只保留在后台,而不会出现在所有活动的应用程序之前。有没有办法让它领先于所有活动的应用程序?谢谢,这真的很有帮助。

部分代码如下:

Private Sub CheckBox1_Click()
X1 = Now
If CheckBox1.Value = True Then TextBox1.Value = Now
If CheckBox1.Value = False Then TextBox1.Value = Null
If CheckBox1.Value = True Then TextBox2.Value = "00:00:00"
TextBox1.BackColor = vbYellow
TextBox2.BackColor = vbYellow
If CheckBox1.Value = True And CheckBox6.Value = False Then
   nTimer = nCounter
   Call RunTimers
End If
If CheckBox1.Value = False Then TextBox2.Value = Null

End Sub

Public Sub RunTimers()    ' Hypothesis initial and Management Bridge on Validation action
 If nTimer > 1 Then
        nTimer = nTimer + 1
        UserForm1.lblsla1.Caption = Format(TimeSerial(0, 0, nTimer), "hh:mm:ss")
        Application.OnTime Now + TimeSerial(0, 0, 1), "RunTimers"

    If nTimer = 1500 Then    '25 minutes
    'MsgBox "HY IS DUE IN NEXT 5 MINUTES", vbOKOnly, reminder
    HYIReminder.Show
    End If
    If nTimer = 12600 Then   '3.5 hours
    'MsgBox "MB IS DUE IN NEXT 5 MINUTES", vbOKOnly, reminder
    MBReminder.Show
    nTimer = 0
    End If
    If UserForm1.CheckBox1.Value = False Then
       nTimer = 0
       UserForm1.lblsla1.Caption = ""
    End If
 End If
End Sub

尝试更改:

MBReminder.Show
HYIReminder.Show

:

MBReminder.Show vbModeless
HYIReminder.Show vbModeless

关于非模态和模态表单的一些细节。没有必要从头到尾看一遍,只看前几行就足够了!

最新更新