Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
208 views
in Technique[技术] by (71.8m points)

VBA coding - Read email by subject, paste in excel, past and separate specific data

I am new to VBA coding. I have a code which allows to search my Outlook inbox for a specific Subject and pastes the body of the email into the first column. I have gotten it to separate each email, but it it is only pasting in one column and also the entire email. Each email contains a table and I only want the table to be put into excel. Any ideas ? The table has 6 columns "ID" "Type" "Last Name" "First Name" "Doc Type" and "Doc Description"

All I really am looking for is a code that takes the body I have imported from the current code and removed everything, but the table

the Body looks like

The following are available for viewing:

(This is the table)

ID Type LAST_NAME FIRST_NAME DOC_TYPE Doc_Description
00000 test DOE John 0000 0000

Report : DocType Report Source: IS reports = 0000

Sub GetFromInbox()

Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olFldr As Outlook.MAPIFolder
Dim olItms As Outlook.Items
Dim olMail As Variant
Dim i As Long

Set olApp = New Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olFldr = olNS.GetDefaultFolder(olFolderInbox)
Set olItms = olFldr.Items

olItms.Sort "Subject"

i = 1

 lrow = 1


For Each olMail In olItms
    If InStr(1, olMail.Subject, "Test ") > 0 Then
        ThisWorkbook.Sheets("Sheet1").Cells(i, 1).Value = olMail.Body
        i = i + 1
    End If
Next olMail

Set olFldr = Nothing
Set olNS = Nothing
Set olApp = Nothing

 
End Sub
question from:https://stackoverflow.com/questions/65907385/vba-coding-read-email-by-subject-paste-in-excel-past-and-separate-specific-d

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...