设置多页值属性崩溃 Excel

Setting Multipage Value Attribute Crashes Excel

我有一个多页用户窗体控件,其中包含两个页面和用于取消、返回、下一步和完成的按钮控件。

当我通过减去 1 在 "back" 按钮子中设置 multipage.value 属性时,Excel freezes/hangs.

Private Sub btn_Back_Click()
        ' Set the buttons
        Me.btn_Next.Enabled = True
        Me.btn_Finish.Enabled = False
        Me.btn_Back.Enabled = False
        Me.multipage_add_xfr.value = Me.multipage_add_xfr.value - 1
End Sub

通过将 1 添加到第二页 "advance" 的代码在 btn_Next_Click() sub:

中工作正常
 Me.multipage_add_xfr.value = Me.multipage_add_xfr.value + 1

最后,在 UserForm_Initialize() 上,将多页控件设置为第一页(例如值 = 0)也会崩溃 Excel。

Me.multipage_add_xfr.value = 0

更新 以下代码适用于在当前项目中创建的新用户窗体,但旧用户窗体不起作用。

Private Sub CommandButton1_Click()
      Me.CommandButton1.Enabled = False
      Me.CommandButton2.Enabled = True
      Me.MultiPage1.value = Me.MultiPage1.value + 1
End Sub

Private Sub CommandButton2_Click()
      Me.CommandButton2.Enabled = False
      Me.CommandButton1.Enabled = True
      Me.MultiPage1.value = Me.MultiPage1.value - 1
End Sub

Private Sub UserForm_Initialize()
      Me.CommandButton2.Enabled = False
      Me.CommandButton1.Enabled = True
      Me.MultiPage1.value = 0
End Sub

想法?

试试这个。

Private Sub btn_Back_Click()
    If multipage_add_xfr.Value < 1 Then Exit Sub '<~~ Add this one line

    Me.btn_Next.Enabled = True
    Me.btn_Finish.Enabled = False
    Me.btn_Back.Enabled = False
    Me.multipage_add_xfr.Value = Me.multipage_add_xfr.Value - 1
End Sub

Lastly, on UserForm_Initialize(), setting the multipage control to the first page (e.g. value = 0) also crashes Excel.

在这种情况下,删除控件并重新创建它。如果仍然没有帮助,那么您可能需要重新创建表单...

您可能还想检查在 Private Sub UserForm_Activate() 中将其设置为 0 是否可以解决问题?

Note the change to lower case that vba forces on my code - is that indicative of a problem? – Zephyr Mays 54 mins ago

这通常发生在您声明同名变量时

来自聊天:文件Post Mortem证实了我的怀疑。有一个用相同名称声明的变量。

Public Sub update(ByVal value As Long, _
                  Optional ByVal MaxValue As Long = 0, _
                  Optional ByVal Status As String = "", _
                  Optional ByVal DisplayPercent As Boolean = True)

Multipage 也已损坏。更换控件解决问题。