关闭窗体并将其设置为vbModeless时,如何等待特定代码运行? [英] How can I wait for a specific code to run while when form is closed and is set to vbModeless?
问题描述
我有一个宏,该宏会生成一个报告,以表明我们当天的银行和会计记录都用完了.在宏末尾,仅在检测到差异时显示UserForm
,并允许用户在处理了差异后将其从ListBox
中删除.
I have a macro that generates a report to show that our bank and accounting records tie out for the day. In the end of the macro a UserForm
displays only if a discrepancy is detected and allows the user to remove it from the ListBox
once they have taken care of the discrepancy.
为了使用户能够在保持UserForm
打开(以跟踪差异)的同时分析输入数据(将其输入到单独的工作表中的工作簿中),只需设置UserForm.Show vbModeless
.现在的问题是,我正在尝试实现一个新功能,以便在UserForm
关闭 后运行,但是当它处于Modeless
状态时,它只是检查条件是否满足并移动在.
In order for the user to analyze the input data (which is imported into the workbook on a separate sheet) while keeping the UserForm
open (to track the discrepancies), I simply set the UserForm.Show vbModeless
. My issue is now that I'm trying to implement a new function to run after the UserForm
is closed but with it in a Modeless
state, it simply checks if the condition is met and moves on.
我试图在OKButton
事件侦听器中实现GoTo X
,但是当从UserForm
内部引用时,我不确定如何在主Module
中的一行中添加代码GoTo
.
I tried to implement a GoTo X
in the OKButton
event listener, but I'm not sure how to have the code GoTo
a line in the main Module
when referenced from within the UserForm
.
我的问题:如何将UserForm
设置为Modeless
,并允许用户在打开数据的情况下浏览数据,但是除非关闭/卸载/按下OkButton,否则不能继续执行代码?
My Question: How can I keep this UserForm
set as Modeless
, and allow the user to navigate through the data with it open, but not continue code unless it's closed / unloaded / OkButton is pressed?
这是按钮Listener:
Here's the button Listener:
Private Sub OKButton_Click()
'.... Code here
Me.Hide
LeftoverValues.Closed = true '(other UserForm if discrepancies not taken care of)
Closed = true 'boolean to flag this as closed
GoTo UnmatchedSummaryClosed: '(name of form, GoTo Line in module)
End Sub
这是宏结尾的代码-从调用UserForm
到结尾:
Here's the code for the end of the macro - from calling UserForm
to end:
'... Approx 2000 lines worth of code leading to this
Application.ScreenUpdating = True
Beep 'To alert users that it's 'finished'
If WireValues.Count > 0 Or BWGPValues.Count > 0 Then
Call DifferenceForm 'Discrepancy UserForm - Named UnmatchedSummary
End If
Beep 'alert to show discrepancy check is done - shows if needed
Call warnForm
UnmatchedClosed: 'INTENDED GoTo LINE FROM USERFORM
If UnmatchedSummary.Closed And LeftoverValues.Closed And WarningForm.Closed Then
Call ARSummary
End If
Call StopTimer(time1, Started1) 'Timer to show how long macro took
Debug.Print "Total Time: " & ShowTime(time1) & "ms"
If UnmatchedSummary.Closed And WarningForm.Closed And ARSummaryDone Then
End 'Also want this to happen only if everything's done
End If ' Don't want data to hang if user doesn't close macro template
End Sub
推荐答案
您可以尝试在要关闭的用户窗体时触发的UserForm_Terminate()
中调用要运行的函数.
You can try putting a call to the function you want to run in the UserForm_Terminate()
which fires when the userform is closed.
这篇关于关闭窗体并将其设置为vbModeless时,如何等待特定代码运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!