VBA Access - Outlook vs Access



Insira todos os seus e-mail no seu banco de dados.

Private Sub ReadInboxInsertDB()
    
    Dim TempRst As DAO.Recordset
    Dim Rst As DAO.Recordset
    Dim OlApp As Outlook.Application
    Dim Inbox As Outlook.MAPIFolder
    Dim InboxItems As Outlook.Items
    Dim Mailobject As Object
    Dim db As DAO.Database
    Dim dealer As Integer

    Set db = CurrentDb

    Set OlApp = CreateObject("Outlook.Application")
    Set Inbox = OlApp.GetNamespace("Mapi").GetDefaultFolder(olFolderInbox)
    Set TempRst = CurrentDb.OpenRecordset("TBL_MAIL")

    With TempRst
        .MoveFirst
    End With
    
    Set InboxItems = Inbox.Items

    For Each Mailobject In InboxItems
        If Mailobject.UnRead Then
            With TempRst
                If Mailobject.Subject = "A&A" Or Mailobject.Subject = "InAnyPlace" Then
                    .AddNew

                    Let !Subject = Mailobject.Subject
                    Let !from = Mailobject.SenderName
                    Let !To = Mailobject.To
                    Let !Body = Mailobject.Body
                    Let !DateSent = Mailobject.SentOn

                    .Update

                    Let Mailobject.UnRead = False
                End If
            End With
        End If
    Next

    Set OlApp = Nothing
    Set Inbox = Nothing
    Set InboxItems = Nothing
    Set Mailobject = Nothing
    Set TempRst = Nothing

End Sub

TagsVBA, Outlook, Access

Nenhum comentário:

Postar um comentário

diHITT - Notícias