Hi,
I have to create a code, that retrieves the emails from outlook.
I can't create any Outlook.Applicaton object, and i can't write code in outlook, so i have to make the code in excel.
Here is what i've got:
So, that's it, but this is retreving all of the mails from the Inbox, but i have to retrieve from a specific folder.Sub GetAddressFromCDO() Dim objSession As MAPI.Session Dim objInboxMsgs As MAPI.Messages Dim objMsg As MAPI.Message Dim strAddress As String Const g_PR_SMTP_ADDRESS_W = &H39FE001F Set objSession = CreateObject("MAPI.Session") objSession.Logon NewSession:=False Set objInboxMsgs = objSession.Inbox.Messages For Each objMsg In objInboxMsgs strAddress = objMsg.Sender.Address If Not InStr(strAddress, "@") Then On Error Resume Next strAddress = objMsg.Sender.Fields(g_PR_SMTP_ADDRESS_W).Value End If cim = strAddress kuldo = objMsg.Sender targy = objMsg.Subject szoveg = objMsg.Text leveldatum = objMsg.TimeReceived Dim cnn As ADODB.Connection Dim cmd As ADODB.Command Dim rs As ADODB.Recordset Dim strDbPath As String Dim strconnect As String Set cnn = New ADODB.Connection cnn.CommandTimeout = 10 Set cmd = New ADODB.Command Set rs = New ADODB.Recordset strDbPath = "\\somewhere on my drive\database.mdb" cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" _ & "Data Source=" & strDbPath cnn.Open rs.Open "tabla", cnn, adOpenDynamic, adLockOptimistic, adCmdTable rs.AddNew rs!Datum = leveldatum rs!Felado_cime = cim rs!Felado_neve = kuldo rs!Uzenet_targya = targy rs!Uzenet_szoveg = szoveg rs.Update rs.Close cnn.Close Set rs = Nothing Set cnn = Nothing Next objSession.Logoff Set objMsg = Nothing Set objInboxMsgs = Nothing Set objSession = Nothing End Sub
I have to use this macro on an outlook which has 4 mailboxes, and i have to retrieve the mails from one specific mailbox's inbox, not all of them.
Please help.
Thx!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks