麻烦各位帮忙分析下,这里为什么提示“应用程序定义或对象定义错误”
一个很简单的小程序,不知道为什么运行到这里总是提示“应用程序定义或对象定义错误”,请各位帮我分析一下,谢谢!有时候程序运行时正常的,但有时候就提示“应用程序定义或对象定义错误”,重启后也依然提示“应用程序定义或对象定义错误”。
我试了下,如果按F8逐句运行该程序就不会有错误提示。
程序代码:
Private Sub CommandButton1_Click() Dim value As Integer If Form1.TextBox1.Text = "" Or Form1.TextBox2.Text = "" Then MsgBox "请填写完整的序列号。", , "输入错误!" value = MsgBox("请填写完整的序列号。", , "输入错误!") If value = 1 Then Exit Sub End If ElseIf IsNumeric(Form1.TextBox2.Text) = False Then MsgBox "流水号只能填写数字,请重新输入", , "输入错误!" value = MsgBox("流水号只能填写数字,请重新输入", , "输入错误!") If value = 1 Then Exit Sub End If Else Dim i% Dim j% Dim m As String Dim n% Dim t% m = Form1.TextBox1.Text n = Form1.TextBox2.Text For j = 1 To 6 Step 2 For i = 1 To 297 t = i - 1 If t = 0 And j = 1 Then Cells(i, j) = m & n ElseIf t = 0 And j = 3 Then n = Right(Cells(i + 10, 1), 4) + 1 Cells(i, j) = m & n ElseIf t = 0 And j = 5 Then n = Right(Cells(i + 10, 3), 4) + 1 Cells(i, j) = m & n ElseIf t Mod 11 = 0 And j = 1 Then n = Right(Cells(i - 1, 1), 4) + 23 Cells(i, j) = m & n ElseIf t Mod 11 = 0 And j = 3 Then n = Right(Cells(i + 10, 1), 4) + 23 Cells(i, j) = m & n ElseIf t Mod 11 = 0 And j = 5 Then n = Right(Cells(i + 10, 3), 4) + 23 Cells(i, j) = m & n Else Cells(i, j) = m & n End If n = n + 1 Next Next End If Unload Form1 End Sub
测试.rar
(19.07 KB)
[此贴子已经被作者于2022-11-28 12:38编辑过]