【问题标题】:Using Microsoft Access, need to pull attachments from Outlook emails of a different account使用 Microsoft Access,需要从其他帐户的 Outlook 电子邮件中提取附件
【发布时间】:2020-06-30 08:05:01
【问题描述】:

我有下面的工作代码来从我自己的 Outlook 电子邮件帐户中提取附件,但是我需要为另一个帐户执行此操作,该帐户设置为自动流程的默认回复电子邮件框。

我不完全确定如何告诉下面的代码检查那个邮箱而不是我自己的。我尝试了设置收件箱变量的不同变体,但到目前为止,它们都没有奏效。这是在 Access 2013 中完成的。

Private Sub GetAttachments()

    Dim ns As Namespace
    Dim Inbox As Outlook.MAPIFolder
    Dim Item As Object
    Dim Atmt As Outlook.Attachment
    Dim FileName As String

    Set ns = GetNamespace("MAPI")

    Set Inbox = ns.GetDefaultFolder(olFolderInbox)

    If Inbox.Items.Count = 0 Then
        MsgBox "There are no messages in the Inbox.", vbInformation, _
                "Nothing Found"
        Exit Sub
    End If

    For Each Item In Inbox.Items
        For Each Atmt In Item.Attachments
            If Atmt.Type = 1 And InStr(Atmt, "xlsx") > 0 Then
                FileName = "C:\attachments\" & Atmt.FileName
                Atmt.SaveAsFile FileName
            End If
        Next Atmt
    Next Item

End Sub

【问题讨论】:

    标签: vba outlook


    【解决方案1】:

    试试这个:

    Set Inbox = ns.Folders("MailboxName").Folders("Inbox")
    

    【讨论】:

    • 其实我自己也发现了这一点;问题是我试图使用电子邮件地址或 AD 名称,而不是邮箱的字面名称(两个带空格的单词等等)。将标记为答案;谢谢你的回复。
    • 此代码假定邮箱已在当前配置文件中打开,并且收件箱实际上称为“收件箱”(在其他语言中不是这样)。
    【解决方案2】:

    使用命名空间.GetSharedDefaultFolder

    Set recip = ns.CreateRecipient("other mailbox owner")
    recip.Resolve
    Set Inbox = ns.GetSharedDefaultFolder(recip, olFolderInbox)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-19
      • 1970-01-01
      • 2015-11-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多