我正在构建一个宏,当我进入电子邮件正文以检查收件人的电子邮件地址时,该宏会自动运行。
我无法将收件人的地址加载到变量中。
Sub BuildTable()
Dim myItem As Outlook.MailItem
Dim myRecipient As String
Set myItem = Application.CreateItem(olMailItem)
Set myRecipient = myItem.Recipient.Address
....
答案 0 :(得分:0)
我不确定您使用的是哪个版本的Outlook,但根据Microsoft(http://msdn.microsoft.com/en-us/library/office/aa211006(v=office.11).aspx),您需要使用.Recipients(Index)来获取收件人。从那里你可以得到地址。我还看到了一些附加到.Recipients的ResolveAll方法,尽管引用了Outlook 2000(eww)。
尝试
Dim myItem As Outlook.MailItem
Dim myRecipient as String
Set myItem = Application.CreateItem(olMailItem)
Set myRecipient = myItem.Recipients.Item(0).Address
这将为您提供第一个收件人的地址(注意我不记得VBA是从索引0还是1开始,如果你得到IndexOutOfRange,则更改为1)。如果你需要其他人,你需要做一个循环。像这样:
For Each Recipient in myItem.Recipients
// do some stuff here
Next Recipient
希望这有帮助。
答案 1 :(得分:0)
您似乎在MS Outlook和Active Inspector中运行,因此可能:
Sub CheckAddresses()
Dim oEmail As Outlook.MailItem
Dim r As Recipient
Dim rList As Recipients
Set oEmail = Application.ActiveInspector.CurrentItem
Set rList = oEmail.Recipients
rList.ResolveAll
For Each r In rList
Debug.Print r.Address
Next
End Sub
答案 2 :(得分:0)
这段代码最终看起来像是:
Sub BuildTable1()
Dim oEmail As Outlook.MailItem
Set oEmail = Application.ActiveInspector.currentItem
Set xlApp = CreateObject("Excel.Application")
xlApp.Application.Visible = True
xlApp.workbooks.Open FileName:= file location
xlApp.WorkSheets("Contacts").Activate
xlApp.Range("A6").Value = oEmail.To
//filtering by value, copying, pasting, etc.
End Sub
-ZL