重新启动后,UserForm冻结

时间:2015-11-06 03:10:43

标签: excel vba

我的第一个UserForm叫做DOORFORM。它有三个按钮,可以打开三个不同的用户表单。用户将单击其中一个按钮,它将打开一个相应的用户表单。

在这种情况下,我可以说他点击 ALUMDRBTN 并打开UserForm ALUMFORM

填写表单后,用户单击 ADDBTN ,然后关闭 ALUMFORM 。当 ALUMFORM 关闭时, DOORFORM 会自动显示(与其他两个表单相同)。

然后用户再次单击 ALUMDRBTN 并填写UserForm。这次当用户单击 ADDBTN Excel冻结时,关闭它的唯一方法是使用任务管理器。

这是我的问题。如果我使用其他UserForms,也会发生同样的事情。

DOORFORM:

Private Sub ALUMDRBTN_Click()
Unload Me
ALUMFORM.Show    
End Sub

Private Sub HMDRBTN_Click()
Unload Me
HMFORM.Show
End Sub

Private Sub PRODRLIST_Click()
RunPython ("import  testconvertworking;testconvertworking.test_with_file()") 
End Sub

Private Sub WDDRBRN_Click()
Unload Me
WDFORM.Show
End Sub

ALUMFORM:

Private Sub ADDBTN_Click()
Dim DR_NUM As String
Dim DR_TYPE As String
Dim DR_HW As String
Dim DR_WIDTH As String
Dim DR_HEIGHT As String
Dim DR_THICKNESS As String
Dim DR_REMARKS As String
Dim DR_MODEL As String
Dim VISIONLT As String
Dim GLASS_LOUVER As String
Dim DR_FRAME As String
Dim DR_FINISH As String
Dim WIDTH_DES As String
Dim HEIGHT_DES As String
Dim VISIONLT_DES As String
Dim GLASS_LOUVER_DES As String
Dim PAIRORSINGLE As String
Dim Ret As Long

DR_NUM = DRNUMBOX.Value
DR_TYPE = DRTYPEBOX.Value
DR_HW = DRHWBOX.Value
DR_WIDTH = DRWIDTHBOX.Value
DR_HEIGHT = DRHEIGHTBOX.Value
DR_THICKNESS = DRTHICKNESSBOX.Value
DR_REMARKS = REMARKSBOX.Value
DR_MODEL = MODELBOX.Value
VISIONLT = VISIONLTBOX.Value
GLASS_LOUVER = GLLVBOX.Value
DR_FRAME = TUBEBOX.Value
DR_FINISH = FINISHBOX.Value

If PAIRBOX.Value = True Then PAIRORSINGLE = "PAIR OF "
If PAIRBOX.Value = False Then PAIRORSINGLE = ""

If DR_WIDTH = "306 mm / 1'-0""" Then WIDTH_DES = "(1'-0"")"
If DR_WIDTH = "381 mm / 1'-3""" Then WIDTH_DES = "(1'-3"")"
If DR_WIDTH = "457 mm / 1'-6""" Then WIDTH_DES = "(1'-6"")"
If DR_WIDTH = "533 mm / 1'-9""" Then WIDTH_DES = "(1'-9"")"
If DR_WIDTH = "610 mm / 2'-0""" Then WIDTH_DES = "(2'-0"")"


If DR_HEIGHT = "1829 mm / 6'-0""" Then HEIGHT_DES = "(6'-0"")"
If DR_HEIGHT = "1981 mm / 6'-6""" Then HEIGHT_DES = "(6'-6"")"
If DR_HEIGHT = "2032 mm / 6'-8""" Then HEIGHT_DES = "(6'-8"")"


If VISIONLT = "NONE" Then
    VISIONLT_DES = ""
Else
    VISIONLT_DES = ", " & VISIONLT
End If

If GLASS_LOUVER = "NONE" Then
    GLASS_LOUVER_DES = ""
Else
    GLASS_LOUVER_DES = ", " & GLASS_LOUVER
End If

With Sheets("DOORS").Range("A" & Rows.Count).End(xlUp)
     .Offset(1).Value = DR_NUM
End With

With Sheets("DOORS").Range("B" & Rows.Count).End(xlUp)
    .Offset(1).Value = "TYPE " & DR_TYPE & ", HW# " & DR_HW
End With

With Sheets("DOORS").Range("C" & Rows.Count).End(xlUp)
    .Offset(1).Value = PAIRORSINGLE & WIDTH_DES & " x " & HEIGHT_DES & "   SPECIAL LITE " & DR_MODEL _
    & GLASS_LOUVER_DES & VISIONLT_DES & ", WITH " & DR_FRAME & " TUBE   FRAME, " & DR_FINISH
End With

With Sheets("DOORS").Range("D" & Rows.Count).End(xlUp)
    .Offset(1).Value = DR_REMARKS
End With

End Sub

Private Sub CommandButton1_Click()
Dim answer As Integer

 answer = MsgBox("DO YOU WANT TO DELETE THE LAST ROW?", vbYesNo + vbQuestion, "REMOVE LAST DOOR")

 If answer = vbYes Then
    Lastrow = Sheets("DOORS").Cells(Rows.Count, 1).End(xlUp).Row
    Range("A" & Lastrow & ":D" & Lastrow).Select
    Selection.Delete Shift:=xlUp
 Else
    'do nothing
 End If

 End Sub

 Private Sub UserForm_Initialize()
 With DRWIDTHBOX
     .AddItem "306 mm / 1'-0"""
     .AddItem "381 mm / 1'-3"""
     .AddItem "457 mm / 1'-6"""
     .AddItem "533 mm / 1'-9"""
     .AddItem "610 mm / 2'-0"""
     .AddItem "686 mm / 2'-3"""
     .AddItem "711 mm / 2'-4"""

  End With

  End Sub

  Private Sub userform_terminate()

  DOORFORM.Show

  End Sub

1 个答案:

答案 0 :(得分:0)

ALUMFORM没有卸载,这肯定会导致一些问题。

在ALUMFORM UserForm_Terminate事件中,您正在尝试DOORFORM.Show(您无法同时显示两个Modal个用户表单。

您可以通过不使用表单的事件处理程序来尝试Show另一个模式显示的表单来解决此问题。

或者,使用Show vbModeless显示表单,而不是卸载表单,执行Me.Hide