如何从 Outlook 联系人中获取列中列出的姓名的电子邮件地址? [英] How to get Email address from outlook contacts for the names listed in a column?

查看:32
本文介绍了如何从 Outlook 联系人中获取列中列出的姓名的电子邮件地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 VBA 新手,我需要帮助做某事:

I am new to VBA and I need help doing something:

如下图所示,我有一个名字列表.我想要做的是根据他们在 A 列中的姓名,从 Outlook 联系人列表(电子邮件地址分散在不同的联系人文件夹中)检索他们的电子邮件地址,并将它们粘贴到 B 列中.

As seen in the picture below, I have a list of names. And what I want to do is retrieve their email address, based on their names in column A, from outlook contact list(the email addresses are scattered in different contact folders) and paste them into column B.

或者,是否可以从 Outlook 联系人中获取每个姓名的电子邮件地址,并使用 Outlook 自动向他们发送电子邮件,以便我可以摆脱 B 列.

Or, Is it possible to get the email address from outlook contacts, for each name and send an email to them automatically with outlook so that I can get rid of the column B.

推荐答案

此代码假定名称在 A 列中.它还假定您正在访问的地址簿的名称名为联系人",并且它们是根据您的图表格式化.

This code assumes names are in column A. It further assumes that the name of the address book you are tapping into is named "Contacts", and that they are formatted according to your diagram.

Option Explicit 
Private Sub GetAddresses() 
Dim o, AddressList, AddressEntry 
Dim c As Range, r As Range, AddressName As String 
Set o = CreateObject("Outlook.Application") 
Set AddressList = o.Session.AddressLists("Contacts") 
 'Change this range accordingly
Set r = Range("A1:A25") 
  For Each c In r 
    AddressName = c.Value 
    For Each AddressEntry In AddressList.AddressEntries 
        If AddressEntry.Name = AddressName Then 
            c.Offset(0, 1).Value = AddressEntry.Address 
            Exit For 
        End If 
    Next AddressEntry 
  Next c 
End Sub 

如果地址在全局地址列表中,则在 Outlook 中,转到工具--> 通讯簿.然后使用下拉列表确定您的地址所在的列表.将代码中的联系人"替换为存储地址的地址簿名称.

If the addresses are in the Global Address List, In Outlook, go to Tools--> Address Book. Then use the drop-down list to identify which list your addresses are in. Replace "Contacts" in the code with the name of the address book the addresses are stored in.

这不是我写的,我是在 Ozgrid 上找到的,并修改了一些内容以适应您的情况.可能需要对您的应用程序进行一些调整.希望这对您有所帮助或让您朝着正确的方向前进.

I didn't write this, I found it on Ozgrid and modified a couple of things to fit your situation. It may take a little tweaking for your application. Hope this helps or gets you going in the right direction.

这篇关于如何从 Outlook 联系人中获取列中列出的姓名的电子邮件地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆