从收件箱中的所有类型中提取发件人详细信息 [英] Extracting sender details from all types in Inbox
问题描述
大家好
我正在尝试通过我的收件箱创建一个简单的循环,它将提取发件人的电子邮件地址和发送时间并创建一个新的Excel工作表(保存到我的文件)并将详细信息粘贴在那里,将已处理的电子邮件保存并移动到
命名为已处理的文件夹中。
我对excel的VBA没问题,但前景不同水壶的鱼和我正在挣扎,它似乎是在抓住邮件类型(我不知道有不同的类型)下面的代码工作正常,但错过了我尝试的几乎一半的所有消息
几个选项徒劳无功。任何帮助将不胜感激
选项显式
子extractFromInbox()
Dim objNS As Outlook.NameSpace
设置objNS = Application.GetNamespace(" MAPI")
Dim olFolder As Outlook.MAPIFolder
设置olFolder = objNS.GetDefaultFolder(olFolderInbox)
Dim Item As Object
Dim oMail As Outlook.MailItem
Dim strFolderpath As String
strFolderpath = CreateObject(" WScript.Shell" ).SpecialFolders(16)
Dim counter As Long
counter = 0
Dim path As String
path = strFolderpath& "\ recieved email" &安培; CStr(格式(现在,"dd_mm_yyyy_hh_mm_ss"))& " .xlsx"
Dim destFolder As Outlook.MAPIFolder
设置destFolder = Session.GetDefaultFolder(olFolderInbox).Parent.Folders(" ;已加工")
Dim xlApp作为对象
Dim wbk作为对象
设置xlApp = CreateObject(" Excel.Application")
xlApp.Application.Visible = True
设置wbk = xlApp.Workbooks.Add
wbk.SaveAs路径
On Error Resume Next
每件物品在olFolder.Items中,
 如果TypeName(Item)=" MailItem"然后
     设置oMail =项目
      wbk.worksheets(1).Range(" A1")。Offset(counter,0)= Item.SenderEmailAddress
      wbk.worksheets(1).Range(" A1")。Offset(counter,1)= oMail.ReceivedTime
      oMail.Move destFolder
      counter = counter + 1
 结束如果
下一页
错误转到0:
wbk.Save
wbk.Close
结束子
Hello Daniel,
>工作正常,但错过了几乎所有消息的一半
很可能是由于代码中的以下条件:
如果TypeName(Item)=" MailItem"那么我是对的吗?
您是否尝试调试代码?我建议花一些时间在调试器下,以便更好地了解幕后发生的事情。
你可能会发现
Outlook 2010中的VBA入门 文章很有帮助。
Hi All
I am trying to create a simple loop through my inbox that will extract the sender's email address and time of sending and create a new excel sheet (saved into my documents) and paste the details in there, save and move the processed e-mails into a folder named processed.
I am okay with excel's VBA but outlook is a different kettle of fish and am struggling, It seems to be snagging on the mail type (I didn't know there were different types) the code below works fine but misses almost half of all the messages I have tried several options to no avail. Any help would be greatly appreciated
Option ExplicitSub extractFromInbox()
Dim objNS As Outlook.NameSpace
Set objNS = Application.GetNamespace("MAPI")
Dim olFolder As Outlook.MAPIFolder
Set olFolder = objNS.GetDefaultFolder(olFolderInbox)
Dim Item As Object
Dim oMail As Outlook.MailItem
Dim strFolderpath As String
strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
Dim counter As Long
counter = 0
Dim path As String
path = strFolderpath & "\recieved emails " & CStr(Format(Now, "dd_mm_yyyy_hh_mm_ss")) & ".xlsx"
Dim destFolder As Outlook.MAPIFolder
Set destFolder = Session.GetDefaultFolder(olFolderInbox).Parent.Folders("Processed")
Dim xlApp As Object
Dim wbk As Object
Set xlApp = CreateObject("Excel.Application")
xlApp.Application.Visible = True
Set wbk = xlApp.Workbooks.Add
wbk.SaveAs path
On Error Resume Next
For Each Item In olFolder.Items
If TypeName(Item) = "MailItem" Then
Set oMail = Item
wbk.worksheets(1).Range("A1").Offset(counter, 0) = Item.SenderEmailAddress
wbk.worksheets(1).Range("A1").Offset(counter, 1) = oMail.ReceivedTime
oMail.Move destFolder
counter = counter + 1
End If
Next
On Error GoTo 0:
wbk.Save
wbk.Close
End Sub
Hello Daniel,
> works fine but misses almost half of all the messages
Most probably it is due to the following condition in the code:
If TypeName(Item) = "MailItem" ThenAm I right?
Did you try to debug the code? I'd suggest spending some time under the debugger for getting better understanding what is going on under the hood.
You may find the Getting Started with VBA in Outlook 2010 article helpful.
这篇关于从收件箱中的所有类型中提取发件人详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!