Using Microsoft Access, need to pull attachments from Outlook emails of a different account

别说谁变了你拦得住时间么 提交于 2019-12-25 04:46:21

问题


I have working code below to extract attachments from my own Outlook email account, however I need to do it for a different account that is setup as a default reply email box for an automated process.

I'm not entirely sure how to tell the code below to check for that mailbox instead of my own. I've tried different variations of setting the Inbox variable, but none of them have worked thus far. This is done within 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

回答1:


Try this:

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



回答2:


Use Namespace.GetSharedDefaultFolder

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


来源:https://stackoverflow.com/questions/28310088/using-microsoft-access-need-to-pull-attachments-from-outlook-emails-of-a-differ

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!