假设您有多个帐户附加到 Outlook 客户端,并且希望能够使用 VBA 选择从哪个帐户发送邮件。你做什么工作? MailItem.SendUsingAccount 参数看起来是执行此操作的正确方法,并在其他地方推荐像这儿 https://stackoverflow.com/questions/17977035/ms-access-outlook-2010-how-to-choose-which-account-to-send-email-from or here http://www.slipstick.com/developer/send-using-default-or-specific-account/ or here http://www.rondebruin.nl/win/s1/outlook/account.htm。但是,如果您应用中的示例开发者参考 https://msdn.microsoft.com/en-us/library/office/ff869635.aspx,将 SendUsingAccount 属性设置为有效帐户可能是不可能的。为什么?
这似乎就是答案:您必须将 MailItem 作为对象调暗,并且not作为 Outlook.Mailitem。拥有一个或多个 Exchange 帐户的 Outlook 客户端似乎无法可靠地将帐户分配给 MailItem。但是,由于某些奇怪的原因,如果改为使用 Dim As Object,则可以将帐户附加到该对象。尽管该对象具有 MailItem 的属性,但它的行为更好了??? ...奇怪...
仅使用 Exchange 帐户,我重现了您的结果。问题可能出在您的代码中。
我可以在 mailitem 上设置 SendUsingAccount。
Sub sendFromEachAccount()
Dim olAccounts As Accounts
Dim olMsg As mailItem
Dim i As Long
Dim accountCount As Long
accountCount = Session.Accounts.count
For i = 1 To accountCount
Set olMsg = CreateItem(olMailItem)
Debug.Print "Account: " & i & ": " & "DisplayName: " & Session.Accounts(i).DisplayName
With olMsg
.SendUsingAccount = Session.Accounts.Item(i)
.Display
End With
Next i
ExitRoutine:
Set olMsg = Nothing
End Sub
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)