【问题标题】:How to export outlook attachment to excel?如何将outlook附件导出到excel?
【发布时间】:2014-01-10 16:49:02
【问题描述】:

我尝试使用以下代码将 Outlook 附件导出到 Excedl:

    Public bCancel As Boolean
    Public dDate As Date
    Public sPath As String

Public Sub TESTMACRO()
    Dim MyOlApp As New Outlook.Application
    Dim MyOlExp As Outlook.Explorer
    Dim MySelection As Outlook.Selection
    Dim msg As MailItem
    Dim amount As Long

    Set MyOlExp = MyOlApp.ActiveExplorer
    Set MySelection = MyOlExp.Selection

    amount = MySelection.Count

    bCancel = True
    TESTMACROX.Show

    If Not bCancel Then

        If amount = 1 Then

            WaitFinish.Show (False)

            Dim objTesteInforme As New TesteInforme

            objTesteInforme.fecha = dDate
            objTesteInforme.path = sPath

            ' Procesamos el mensaje seleccionado
            If MySelection.Item(1).Class = olMail Then
                ' El objeto seleccionado es un correo
                Set msg = MySelection.Item(1)
                If InStr(1, msg.Subject, "YYYYY") > 0 And InStr(1, msg.Subject, "ZZZZZ") > 0 Then

                    ' Se trata de un mensaje de xxxxxxxxxxxxxxxxxx

                    objTesteInforme.CLIENTE = "YYYYYZZZZZ"

                    If (Not objTesteInforme.GeneraTestMacro(msg)) Then
                        ' El procesamiento fracasó
                        MsgBox "El procesamiento del mensaje " & msg.Subject & " fracasó; por favor, revisa el formato del archivo adjunto", vbCritical
                    End If
                                                Else
                                                    MsgBox "El mensaje " & msg.Subject & " no se reconoce como diario Batch de ningún cliente", vbCritical
                                                End If
                End If
                Set msg = Nothing
            Else
                MsgBox "Por favor, selecciona un correo electrónico", vbExclamation
            End If

            WaitFinish.Hide
            Else
                MsgBox "Por favor selecciona uno y solo un mesaje. Gracias", vbExclamation
            End If

        Set MySelection = Nothing
        Set MyOlExp = Nothing

    End Sub

问题是我只选择了一条消息,主题为 YYYYY ZZZZZ - LLLLLLL: 140109,但它没有打开带有附件的 Excel 工作表,而是发送错误消息“Por喜爱selecciona uno y solo un mesaje。Gracias” .为什么?

【问题讨论】:

    标签: excel outlook vba


    【解决方案1】:

    我尝试了您的代码,但无法将西班牙语方法正确翻译成英文(我找不到 New TestInforme 的等价物)。

    根据错误消息,您的循环逻辑似乎失败了。尽量不要使用负循环。比如:

    ...
    If bCancel=False then
        ...
    Else
        MsgBox 
    End If
    ...
    

    【讨论】:

    • 'TesteInforme' 是我给我的工作簿起的名字(这是一种从 Excel 中引用对象的方法)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多