Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub impOutlookTable()
- ' point to the desired email
- Const strMail As String = "bahadir.kara@alacergold.com"
- Dim oApp As Outlook.Application
- Dim oMapi As Outlook.MAPIFolder
- Dim oMail As Outlook.MailItem
- On Error Resume Next
- Set oApp = GetObject(, "OUTLOOK.APPLICATION")
- If (oApp Is Nothing) Then Set oApp = CreateObject("OUTLOOK.APPLICATION")
- On Error GoTo 0
- Set oMapi = oApp.GetNamespace("MAPI").Folders(strMail).Folders("Inbox").Folders("AMEC-DCC -DS- TRANSMITTAL")
- Set oMail = oMapi.Items(oMapi.Items.Count)
- ' get html table from email object
- For Each oMail In oMapi.Items
- Dim oHTML As MSHTML.HTMLDocument: Set oHTML = New MSHTML.HTMLDocument
- Dim oElColl As MSHTML.IHTMLElementCollection
- With oHTML
- .Body.innerHTML = oMail.HTMLBody
- Set oElColl = .getElementsByTagName("p")
- End With
- 'import in Excel
- Dim x As Long, y As Long, counter As Long
- SonSatir = Range_End_Method() + 1
- On Error Resume Next
- For x = 0 To oElColl(0).Rows.Length - 1
- On Error Resume Next
- For y = 0 To oElColl(0).Rows(x).Cells.Length - 1
- Range("A" & SonSatir).Offset(x, y).Value = oElColl(0).Rows(x).Cells(y).innerText
- Next y
- Next x
- Set oApp = Nothing
- Set oMapi = Nothing
- Set oMail = Nothing
- Set oHTML = Nothing
- Set oElColl = Nothing
- Next
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement