我正在尝试提取Outlook收件箱中所有电子邮件的电子邮件地址 . 我在互联网上找到了这个代码 .
Sub GetALLEmailAddresses()
Dim objFolder As MAPIFolder
Dim strEmail As String
Dim strEmails As String
''' Requires reference to Microsoft Scripting Runtime
Dim dic As New Dictionary
Dim objItem As Object
''Set objFolder = Application.ActiveExplorer.Selection
Set objFolder = Application.GetNamespace("Mapi").PickFolder
For Each objItem In objFolder.Items
If objItem.Class = olMail Then
strEmail = objItem.SenderEmailAddress
If Not dic.Exists(strEmail) Then
strEmails = strEmails + strEmail + vbCrLf
dic.Add strEmail, ""
End If
我正在使用outlook 2007.当我使用F5从Outlook Visual Basic编辑器运行此代码时,我在以下行中收到错误 .
Dim dic As New Dictionary
"user defined type not defined"
4 回答
我在下面提供了更新的代码
将收件箱电子邮件地址转储为CSV文件“ c:\emails.csv " (the current code provides no " outlook”以获取收集的地址
上面的代码根据您的请求在选定的文件夹而不是收件箱中工作
[Update: For clarity this is your old code that uses "early binding", setting this reference is unnecessary for my updated code below which uses "late binding"]
A部分:您现有的代码(早期绑定)
就您收到的错误而言:
上面的代码示例使用早期绑定,此注释"Requires reference to Microsoft Scripting Runtime"表明您需要设置引用
转到“工具”菜单
选择'References'
检查"Microdoft Scripting Runtime"
B部分:我的新代码(后期绑定 - 不需要设置引用)
工作守则
将文件导出到C:\ Users \ Tony \ Documents \ sent file.CSV
然后使用红宝石
这是使用Exchange的更新版本 . 它将Exchange格式地址转换为普通电子邮件地址(使用@符号) .
感谢http://forums.codeguru.com/showthread.php?441008-Extract-sender-s-email-address-from-an-Exchange-email和Brettdj
在Outlook中,将文件夹导出到csv文件,然后在Excel中打开 . 一个简单的MID函数应该能够提取电子邮件地址,如果它还没有放在“从”列中 .