我有一个宏,它创建一个新电子邮件,代表...发送。但是我不想显式使用硬编码的电子邮件地址,而是询问Outlook已经设置了哪些地址。
我正在考虑使用过滤器(例如....以“ @ myonbehalfdomain.com”结尾)
所以在下面的示例中:Eonbehalf应该获得第二个电子邮件地址,我可以使用新电子邮件中的“发件人”下拉列表来看到该地址。
有道理吗?
Sub CreateNewMail()
Dim olNS As Outlook.NameSpace
Dim oMail As Outlook.MailItem
Set olNS = Application.GetNamespace("MAPI")
Set oMail = Application.CreateItem(olMailItem)
strbody = "<BR><BR><BR>"
SigString = Environ("appdata") & _
"\Microsoft\Handtekeningen\custom.htm"
If Dir(SigString) <> "" Then
Signature = GetBoiler(SigString)
Else
Signature = ""
End If
On Error Resume Next
Eonbehalf = getemailaddress(2)
oMail.SentOnBehalfOfName = Eonbehalf
oMail.Display
oMail.HTMLBody = strbody & Signature
Set oMail = Nothing
Set olNS = Nothing
End Sub
答案 0 :(得分:0)
根据我的经验,可以在Outlook中以两种方式将电子邮件用作“代表发送”:
对于第一种情况,请尝试遍历Accounts集合:
Sub getAccount()
Set oNS = Application.GetNamespace("MAPI")
For Each oAccount In oNS.Accounts
'your code goes here (read oAccount.DisplayName for example)
Next oAccount
End Sub
在后一种情况下:
Sub getFolder()
Set oNS = Application.GetNamespace("MAPI")
For Each oFolder In oNS.Folders
'your code goes here (read oFolder.Name for example)
Next oFolder
End Sub
********************************编辑**************** ************
尝试用fnGetSecondAdress("theEmailDomainYouReLookingFor")
替换getemailaddress(2)
并在代码中添加以下功能
Function fnGetSecondAdress(strDomain As String)
Dim strAddress As String
Set oNS = Application.GetNamespace("MAPI")
For Each oFolder In oNS.Folders
If InStr(1, oFolder.Name, strDomain, vbTextCompare) >= 1 And InStr(1, oFolder.Name, "Public Folders", vbTextCompare) = 0 Then
strAddress = oFolder.Name
End If
Next oFolder
fnGetSecondAdress = strAddress
End Function