简体   繁体   English

从Excel(2013)的备用(不是主要)Outlook(2013)帐户发送电子邮件。 (VBA)

[英]Sending emails from Excel (2013) from an alternate (not main) Outlook (2013) account. (VBA)

I've managed to get Excel to create emails in Outlook, from an alternate account, not my main one. 我设法让Excel在Outlook中通过备用帐户(而不是我的主要帐户)创建电子邮件。

The trouble is, they just sit in the second account Outbox, doing nothing. 麻烦的是,他们只是坐在第二个帐户的发件箱中,什么也不做。 Note that I can send files from this account manually just fine. 请注意,我可以手动从该帐户发送文件。

Dim MyOlApp As Object
Dim MyItem As Outlook.MailItem
Dim AttachName As String
Dim SendTo As String
Dim CCTo As String
Dim E, F, G As Integer
Dim Sys_Date As String
'Sys_Date = Format(Now(), "DD-MMM-YYYY")

F = Application.WorksheetFunction.CountA(Sheets("Sheet2").Range("A:A"))
'G = F


For E = 2 To F

Sheets("Sheet2").Select
AttachName = Cells(E, 2).Value
SendTo = Cells(E, 5).Value
CCTo = Cells(E, 6).Value

Set MyOlApp = CreateObject("Outlook.Application")
Set MyItem = MyOlApp.CreateItemFromTemplate("C:\localDocuments\2 - Reporting\1 - Guides + Sample Data etc\Email.oft")
MyItem.Display

On Error Resume Next
With MyItem
    Set .SendUsingAccount = MyOlApp.Session.Accounts.Item(2)
    .To = SendTo
    .CC = CCTo
    .BCC = ""
    .Subject = "Action required: " & AttachName
    'You can add other files also like this
    .Attachments.Add ("C:\localDocuments\2 - Reporting\Reports\" & AttachName & ".xlsx")
    .Display
    .Send
End With
On Error GoTo 0

Set MyItem = Nothing
Set MyOlApp = Nothing


Next E

UPDATE: 更新:

Whilst I've not been able to find the actual cause of the issue. 虽然我无法找到问题的真正原因。 I have managed to find a very simple fix. 我设法找到一个非常简单的修复程序。

I've created a new Outlook Profile, with just the alternate account that we need to send by and it works just fine. 我创建了一个新的Outlook配置文件,其中仅包含我们需要发送的备用帐户,并且该帐户工作正常。 This works perfectly as the code is only used once a week once a 3hr report has been run. 这非常有效,因为该代码仅在运行3小时报告后每周使用一次。

I can see that it would not be applicable to someone who was sending regular (throughout the day) emails in this way. 我可以看到它不适用于以这种方式发送常规(全天​​)电子邮件的用户。

For Reference, you access the profiles by WIN 8 SEARCH / MAIL (filter by SETTINGS), select MAIL and then VIEW PROFILES. 作为参考,您可以通过WIN 8 SEARCH / MAIL(通过SETTINGS过滤)访问配置文件,选择MAIL,然后选择VIEW PROFILES。

A very simple fix. 一个非常简单的修复程序。

I've created a new Outlook Profile, with just the alternate account that we need to send by and it works just fine. 我创建了一个新的Outlook配置文件,其中仅包含我们需要发送的备用帐户,并且该帐户工作正常。

I acknowledge that it would not be a good fix to someone who was sending regular (throughout the day) emails in this way. 我承认,对于以这种方式定期(全天)发送电子邮件的人来说,这不是一个好的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM