当表单closures并且设置为vbModeless的时候,如何等待特定的代码运行?

我有一个macros,它会生成一个报告,显示我们的银行和会计logging是否为当天。 在macros的末尾, UserForm仅在检测到差异时才显示,并允许用户在处理差异后将其从ListBox移除。

为了让用户在保持UserForm打开的情况下分析input数据(将其导入到工作簿的单独表单中),以便跟踪这些差异,我只需设置UserForm.Show vbModeless 。 我现在的问题是,我正试图实现一个新的function,在UserForm closures后运行,但在Modeless状态下,它只是检查条件是否满足,并继续前进。

我试图在OKButton事件监听器中实现一个GoTo X ,但是我不知道如何从UserForm引用主代码中的代码GoTo一行。

我的问题:如何保持此UserForm设置为Modeless ,并允许用户浏览数据打开,但不继续代码,除非closures/卸载/ OkButton被按下?

这是button监听器:

 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 

下面是macros结束的代码 – 从调用UserForm到结束:

  '... 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()要运行的函数进行调用,该函数在UserForm_Terminate()closures时触发。