使用用户窗体命令按钮标题作为公共变量

时间:2019-06-21 03:33:21

标签: excel vba userform

我有一个用户窗体,上面有几个命令按钮,每个按钮上都有唯一的标题。我打算将标题用作模块中代码内的变量。

单击第一个按钮(commandbutton13)效果很好。但是,当我单击第二个按钮(commandbutton14)时,它仍将第一个按钮(commandbutton13)的标题保留为变量。

Private Sub CommandButton13_Click() 'PRIC Button userform

HoldType = UF_Dashboard.CommandButton13.Caption   'caption is PRIC
HoldText = UF_Dashboard.TextBox5.Value
sCell = UF_Dashboard.TextBox4.Value

'Check for sales order and hold text
If TextBox4.Text = "" Or TextBox5.Text = "" Then
    MsgBox ("You must enter a Sales Order and Hold Text to continue.")
    Exit Sub
End If

Hold

End Sub



Private Sub CommandButton14_Click() 'CUST Button on userform

HoldType = UF_Dashboard.CommandButton14.Caption    'caption is CUST
HoldText = UF_Dashboard.TextBox5.Value
sCell = UF_Dashboard.TextBox4.Value

'Check for sales order and hold text
If TextBox4.Text = "" Or TextBox5.Text = "" Then
    MsgBox ("You must enter a Sales Order and Hold Text to continue.")
    Exit Sub
End If

Hold

End Sub

在模块中,我有以下内容:

Public HoldType as String

我需要帮助来了解为什么在单击commandbutton14之后HoldType为什么显示为PRIC。即使在开发人员模式下,我也无法选择该行,因此我假设它锁定在commandbutton13代码中HoldType的第一个定义上。

0 个答案:

没有答案