在撰写模式下通过VBA在outlook上返回发件人/发件人地址

在撰写模式下通过VBA在outlook上返回发件人/发件人地址,vba,outlook,Vba,Outlook,我在outlook上只有一个exchange帐户,可以访问管理员创建的两个共享/组邮箱或邮件地址。我只是那个共享邮件组的成员,我可以通过它们收发邮件。所以有时候我会选择错误的寄件人地址。在发送电子邮件之前,我需要检查发件人/发件人地址和收件人。但是,我无法通过VBA以字符串形式返回发件人/发件人地址。我通过“从”下拉菜单选择它们 这是我的密码: Dim Recipients As Outlook.Recipients Dim recip As Outlook.Recipient Dim i Di

我在outlook上只有一个exchange帐户,可以访问管理员创建的两个共享/组邮箱或邮件地址。我只是那个共享邮件组的成员,我可以通过它们收发邮件。所以有时候我会选择错误的寄件人地址。在发送电子邮件之前,我需要检查发件人/发件人地址和收件人。但是,我无法通过VBA以字符串形式返回发件人/发件人地址。我通过“从”下拉菜单选择它们

这是我的密码:

Dim Recipients As Outlook.Recipients
Dim recip As Outlook.Recipient
Dim i
Dim prompt As String
Dim Send_Address As String
Dim checker As Integer

Send_Address = Item.SendUsingAccount.SmtpAddress

checker = 0

Set Recipients = Item.Recipients
For i = Recipients.Count To 1 Step -1
    Set recip = Recipients.Item(i)

    If InStr(LCase(recip.Address), "abc.com") Then
    checker = 1
    End If

    If InStr(LCase(recip.Address), "xyz.com") Then
    checker = 2
    End If

Next i

If (Send_Address = "abc.om") And (checker = 1) Then
    MsgBox ("Please check CC list. It includes different clients.")
    Cancel = True
ElseIf (Send_Address = "xyz.com") And (checker = 2) Then
    MsgBox ("Please check CC list. It includes different clients.")
    Cancel = True
Else
    MsgBox ("OK" & checker & Send_Address)
    Cancel = True
End If

End Sub

From值位于
.sentonBehalfName
中。它不会在GUI更改时更新

用代码更新该值。GUI将保持不变

选项显式
子updateFromValue()
将项目设置为邮件项目
Dim mailbox1作为字符串
Dim mailbox2作为字符串
Dim mailbox3作为字符串
作为字符串的Dim resp
'首先创建用于测试的草稿
Set Item=ActiveInspector.currentItem
项目.显示
Debug.Print“.SentonBehalfName:”&Item.SentonBehalfName
mailbox1=“abc.com”
mailbox2=“xyz.com”
mailbox3=“default.com”
resp=InputBox(“1:”&mailbox1&vbCr&“2:”&mailbox2&vbCr&“3:”&mailbox3)
如果Len(resp)>0,则
选择案例响应
案例1
Item.SentonBehalfName=mailbox1
Debug.Print“Item.SentOnBehalfOfName:&Item.SentOnBehalfOfName
案例2
Item.SentonBehalfName=mailbox2
Debug.Print“Item.SentOnBehalfOfName:&Item.SentOnBehalfOfName
案例3
Item.SentonBehalfName=mailbox3
Debug.Print“Item.SentOnBehalfOfName:&Item.SentOnBehalfOfName
其他情况
调试。打印“?”
结束选择
如果结束
端接头

现在,您可以验证应用程序_ItemSend.

.SentOnBehalfOfName
的值。使用SendUsingAccount属性有什么问题?