I dette særtema ser vi på, hvordan cloud og AI bliver fundamentet for virksomhedernes digitale forretning, og hvordan de nye muligheder for automatisering og forretningsværdi kan udnyttes uden at miste overblik, sikkerhed og menneskelig kontrol.
Ok. Her er den, men uden filter og den tager KUN fra indbakken.
Opret en tabel i Access med navnet "tblEMail" og med disse felter : MAIL_FROM MAIL_TO MAIL_CC MAIL_BCC MAIL_Subject MAIL_Body
Som alle er af typen NOTAT og kan indeholde TOMME felter.
Husk også at ændre referencerne i Access så du bruger : "Microsoft DAO 3.x" og "Microsoft Outlook 9.0 Object Library".
Og her kommer så modulet :
Sub ImportEMailFromOutlook()
' This code is based in Microsoft Access.
' Set up DAO objects (uses existing "tblEMail" table) Dim rst As DAO.Recordset Set rst = CurrentDb.OpenRecordset("tblEMail")
' Set up Outlook objects. Dim ol As New Outlook.Application Dim olns As Outlook.Namespace Dim cf As Outlook.MAPIFolder Dim c As Outlook.MailItem Dim objItems As Outlook.Items
Set olns = ol.GetNamespace("MAPI") Set cf = olns.GetDefaultFolder(olFolderInbox) Set objItems = cf.Items iNumMails = objItems.Count If iNumMails <> 0 Then For i = 1 To iNumMails If TypeName(objItems(i)) = "MailItem" Then Set c = objItems(i) rst.AddNew rst!Mail_FROM = c.SenderName rst!Mail_To = c.To rst!Mail_CC = c.CC rst!Mail_BCC = c.BCC rst!Mail_Subject = c.Subject rst!Mail_Body = c.Body rst.Update End If Next i rst.Close MsgBox "Finished." Else MsgBox "No mails to export from Outlook." End If
Det virker fint. Men hvis jeg gerne vil have koden til at logge på exchangeserveren er det så noget større problem. Det er fordi det ikke er min egen mailbox der skal importeres.
Jeg tror dette virker... Du skal bare huske at ændre linien :
olns.Logon "Profile", "password", True, True
til din egen (eller den andens profil) og password.
Sub ImportEMailFromOutlookExchange()
' This code is based in Microsoft Access.
' Set up DAO objects (uses existing "tblEMail" table) Dim rst As DAO.Recordset Set rst = CurrentDb.OpenRecordset("tblEMail")
' Set up Outlook objects. Dim ol As New Outlook.Application Dim olns As Outlook.Namespace Dim cf As Outlook.MAPIFolder Dim c As Outlook.MailItem Dim objItems As Outlook.Items Dim UnR, Re As Integer
Set olns = ol.GetNamespace("MAPI") olns.Logon "Profile", "password", True, True UnR = 0 Re = 0 Set cf = olns.GetDefaultFolder(olFolderInbox) Set objItems = cf.Items iNumMails = objItems.Count If iNumMails <> 0 Then For i = 1 To iNumMails If TypeName(objItems(i)) = "MailItem" Then Set c = objItems(i) rst.AddNew rst!Mail_FROM = c.SenderName rst!Mail_To = c.To rst!Mail_CC = c.CC rst!Mail_BCC = c.BCC rst!Mail_Subject = c.Subject rst!Mail_Body = c.Body If c.UnRead = False Then UnR = UnR + 1 Else Re = Re + 1 End If rst.Update End If Next i rst.Close MsgBox "Finished." & vbCr & "(Ulæst = " & UnR & ", Læst = " & Re & ")" Else MsgBox "No mails to export from Outlook." End If
Sub SimpleImport() Dim dbs As Database Dim strConnect As String Dim strSQL As String Set dbs = CurrentDb 'Build the connection string. strConnect = _ "Exchange 4.0;MAPILEVEL=Mailbox - KiraR|Inbox;DATABASE=" _ & dbs.Name & ";" 'Build the SQL statement. strSQL = _ "SELECT * INTO ImportTable FROM [" & strConnect & "].MyMessages;" 'Run the query. dbs.Execute strSQL 'Refresh the database window and clear database object variable. RefreshDatabaseWindow dbs.Close dbs = Nothing End Sub
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.