如何从Outlook联系人获取列中所列名称的电子邮件地址?

问题描述:

我是VBA的新手,我需要做一些事情的帮助:

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

如下图所示,我有一个名字列表.我想做的就是从Outlook联系人列表中基于他们在A列中的名称检索他们的电子邮件地址(电子邮件地址分散在不同的联系人文件夹中)并将它们粘贴到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列中.它还假定您正在访问的通讯簿的名称被命名为"Contacts",并且它们是根据您的图表进行格式化.

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.