VBA 单击命令按钮时用户窗体未关闭

VBA Userform not closing on command button click

我正在 运行在 Excel VBA 中创建一个用户表单,它似乎可以工作,但是,它似乎并没有关闭。基本上,一旦将数据输入表单并单击 "SUBMIT" 按钮,我希望将数据存储在某些单元格中并关闭表单以及 运行 另一个子代码。

以下是我的VBA代码:

Private Sub CommandButton1_Click()
HaulerRatesForm.Label1.Caption = Worksheets("Dashboard").Range("A47").Value
HaulerRatesForm.Label2.Caption = Worksheets("Dashboard").Range("A48").Value
HaulerRatesForm.Label3.Caption = Worksheets("Dashboard").Range("A49").Value
HaulerRatesForm.Label4.Caption = Worksheets("Dashboard").Range("A50").Value

HaulerRatesForm.Show

End Sub

Private Sub UserForm_Initialize()

End Sub

Private Sub CommandButton2_Click()
Worksheets("Dashboard").Cells(47, "H").Value = HaulerRatesForm.TextBox1.Value
Worksheets("Dashboard").Cells(48, "H").Value = HaulerRatesForm.TextBox2.Value
Worksheets("Dashboard").Cells(49, "H").Value = HaulerRatesForm.TextBox3.Value
Worksheets("Dashboard").Cells(50, "H").Value = HaulerRatesForm.TextBox4.Value

Unload Me

Call Dashboardcodes2

End Sub

我似乎不明白为什么 Unload Me 似乎没有关闭 window。关于我在这里做错了什么有什么想法吗?

感谢 urdearboy, 之前的回答似乎回答了我的问题。

我通过双击直接导航到用户窗体的按钮来使用下面的代码:

Private Sub CommandButton2_Click()
Worksheets("Dashboard").Cells(47, "H").Value = HaulerRatesForm.TextBox1.Value
Worksheets("Dashboard").Cells(48, "H").Value = HaulerRatesForm.TextBox2.Value
Worksheets("Dashboard").Cells(49, "H").Value = HaulerRatesForm.TextBox3.Value
Worksheets("Dashboard").Cells(50, "H").Value = HaulerRatesForm.TextBox4.Value

Unload Me

End Sub

我将代码放在 Unload Me 下的 Dashboardcodes2 中,现在一切正常。