在VBA中切换不同发件人的最简单方法是什么?

时间:2012-02-05 02:57:51

标签: vba excel-vba outlook excel

即,我正在谈论MAPIFolder,MailItem和Recipient对象类型。

-------------------附加信息-------------------------- -----------------

这是我的一些对象:

Dim w As Outlook.Application
Dim wInbox As Outlook.MAPIFolder
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient

2 个答案:

答案 0 :(得分:1)

我正在寻找.SendUsingAccount属性,例如下面的this article

Public Sub New_Mail()
Dim oAccount As Outlook.Account
Dim oMail As Outlook.MailItem

For Each oAccount In Application.Session.Accounts
   If oAccount = "Name_of_Default_Account" Then
      Set oMail = Application.CreateItem(olMailItem)
      oMail.SendUsingAccount = oAccount
      oMail.Display
   End If
Next
End Sub

答案 1 :(得分:0)

如果您的第二个邮箱被称为“其他人”,那么您可以尝试使用它来引用属于它的收件箱(与默认收件箱不同)

Dim objOl As Outlook.Application
Dim objNS As Outlook.Namespace
Dim objFolder As Outlook.MAPIFolder
Set objOl = New Outlook.Application
Set objNS = objOl.GetNamespace("MAPI")
Set objFolder = objNS.Folders("Other Person")
Set objFolder = objFolder.Folders("Inbox")