出现错误462 VBA时,应该如何定义一个excel对象?

时间:2018-08-30 09:22:19

标签: excel vba outlook-vba

我对位于Outlook中的宏有问题。该代码由“私人子”代码触发,该代码创建取决于邮件主题的“ TriggerExcel(1)”或“ TriggerExcel(2)”。

代码被触发时,有时会停留在以下行:Set ExApp = Excel.Application 'Codes

哪里出现以下错误:

enter image description here

我的猜测是代码没有在代码中正确定义excel对象,但是我很难理解应该如何做……任何建议都应得到赞赏。

Public Sub TriggerExcel(Mode As Integer)

        ‘Activate following tool reference:  Tool-References-Microsoft Excel 14.0 Object library -biblioteket
            Dim ExApp As Excel.Application
            Dim ExWbk As Workbook
            Set ExApp = Excel.Application 'Codes

 cause error here

    ExApp.DisplayAlerts = False

    If Mode = 1 Then
        On Error Resume Next
        Set ExWbk = Workbooks("Nyins.xlsm")
        Debug.Print ExWbk.Name
        On Error GoTo 0
        'Set ExWbk = ExApp.Workbooks.Open("C:\Users\linsten\Desktop\Nyins.xlsm")
        ExApp.Visible = False
        'ExWbk.Application.Run "mymain.main"

        If ExWbk Is Nothing Then
        Set ExWbk = ExApp.Workbooks.Open("\\Sca9a\pd-61$\Control\Process\Nyins.xlsm")
        End If

        ExWbk.Application.Run "MainModule.main"

    ElseIf Mode = 2 Then

        Set ExApp = Excel.Application

        On Error Resume Next
        Set ExWbk = Workbooks("Val.xlsm")
        Debug.Print ExWbk.Name
        On Error GoTo 0
        ExApp.Visible = False

        If ExWbk Is Nothing Then
        Set ExWbk = ExApp.Workbooks.Open("\\Sca9a\pd-61$\Control\Process\Daily\Val.xlsm")
        End If

        ExWbk.Application.Run "MyMain.Main"

    End If


        ExWbk.Close
        ExApp.Quit
    End Sub         

0 个答案:

没有答案