运行时错误'424;“对象为案例函数所必需的

时间:2016-07-13 17:29:18

标签: vba

我无法弄清楚下面是代码....我点击第二种情况的错误打开表单frmBookingLCL.show表单名称是正确的。我无法弄清楚这一点。与****行的错误行。 HELP !!

Public Sub SendBookingEmail()
    StartTime = Timer
    With Session
            'check first 2 letters of shipper's code, if not US raise error
            If IsStartPositionCorrect(5, 14, 2, "US") <> True Or IsStartPositionCorrect(5, 2, 8, "Customer") <> True And GetDisplayText(4, 20, 1) <> "0" Then
                If MsgBox("You don't appear to be in Logis ocean export US file. Please enter the file first and then run the macro.", vbOKOnly, "Export file verification....") Then
                    Exit Sub
                End If
            End If

            sTypeOfMessage = "booking"
            sShipmentType = Trim(.GetDisplayText(9, 61, 3))
            sFileType = Trim(.GetDisplayText(4, 32, 1))
            bFullVersion = False

            'On Error GoTo ErrHand

            'Get Outlook if it's running
            Set oOutlookApp = GetObject(, "Outlook.Application")

            'collect data fields for the e-mail body
            GetAllLogisDataBooking


            'Blow up the question form
            Select Case sShipmentType
                Case "FCL", "CMF", "CCS", "FPR"
                    frmBookingFCL.Show
                Case "LCL", "GWY", "CLD"
                    frmBookingLCL.Show**********ERROR HERE
                Case Else
                    frmBookingFCL.Show
                    'frmBookingOthers.Show
            End Select


    End With

    Finish = Timer
    TimeTook = Finish - StartTime
    MyMacroStats = GetProcedureStats("Booking Confirmation", TimeTook)


    Exit Sub

ErrHand:

        If Err = 429 Then
            MsgBox "Please note you must start Microsoft Outlook first."
            End
        End If

End Sub

1 个答案:

答案 0 :(得分:1)

最有可能的错误是您的用户表单。请参阅代码注释。

我试图复制下面的问题:

Sub test()

'/Sub  to load the user form.

Dim x   As String

    x = "a"

    Select Case x
    Case "a", "b", "c"
        UserForm1.Show '/ It Will error-out here during debugging.
    End Select
End Sub

UserForm1中的代码

Private Sub UserForm_Initialize()

    '/ Code from : https://msdn.microsoft.com/en-us/library/office/gg251554.aspx
    '/ Actually the error happens here.

    Dim RetVal ' Implicitly a Variant.
    ' Default property is assigned to Type 8 Variant RetVal.
    RetVal = CreateObject("Excel.Application")
    RetVal.Visible = True ' Error occurs here.
End Sub

所以通过你的初始化代码,要么你缺少,要么其他控件之一的名称不正确。 frTruckerCheckBox1txtPickupDate。一旦你纠正它们,错误就会消失。