我有一个宏生成一份报告,显示我们的银行和会计记录当天就已结合。在宏的末尾,UserForm
仅在检测到差异时显示,并允许用户在处理差异后将其从ListBox
中删除。
为了让用户在保持UserForm
打开(跟踪差异)的同时分析输入数据(在单独的工作表中导入工作簿),我只需设置UserForm.Show vbModeless
。我的问题是,我正在尝试实施一个新功能,以便在UserForm
关闭之后运行,但是在Modeless
状态下,它只会检查条件是否正常满足并继续前进。
我尝试在GoTo X
事件监听器中实现OKButton
,但我不确定如何在主GoTo
中将代码Module
作为一行从UserForm
。
我的问题:如何将此UserForm
设置为Modeless
,并允许用户在数据打开的情况下浏览数据,但不能继续执行代码,除非已关闭/卸载/按下OkButton ?
这是按钮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
到结束:
'... 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
答案 0 :(得分:1)
您可以尝试调用要在用户窗体关闭时触发的UserForm_Terminate()
中要运行的功能。