Excel电子邮件宏大小限制

时间:2016-07-20 14:15:17

标签: vba excel-vba email outlook excel

我制作了一个宏,用于向客户发送批量电子邮件,为每个客户端使用个性化信息。它的工作效果很好,但我刚刚注意到宏在运行宏时在Outlook中填充的第67个草稿后没有创建电子邮件。我已经尝试过研究,并且没有找到约束限制,因为有多少电子邮件草稿可以让您立即打开。我已经在下面发布了我的代码,万一有人可以看到我是否无意中设置了限制。

宏如何运作:员工每个月都有一份关于500个帐户的列表,他们需要通过电子邮件联系我们,以便与我们续签合同。所有信息都在Excel文件中,此宏会提取每个客户的电子邮件地址,客户名称,客户联系人,续订日期等,并在每封电子邮件中使用该信息以获得更个性化的电子邮件。一旦员工点击按钮运行宏,它将为列表中的每个帐户创建一个电子邮件,填充在Outlook中。我在Outlook中填写了电子邮件,而不是自动发送,以防员工根据客户端编辑或向电子邮件添加更多信息。大多数情况下,他们按原样发送电子邮件,但员工会编辑一些电子邮件。因此,虽然让Outlook中的这么多草稿一次性填充似乎令人生畏,但员工以这种方式发送电子邮件的速度要快得多,而不是单独输入每个电子邮件。

因此,当宏应该在最后一行信息中运行时,为什么我不能一次发送超过67封电子邮件的任何建议或见解,请告诉我。如果不是,我只需要告诉员工我只能批量使用60个宏。

Sub SendEMail()


Dim Email As String
Dim Subj As String
Dim Msg As String
Dim URL As String
Dim r As Integer
Dim x As Double
Dim OApp As Object
Dim OMail As Variant
Dim Signature As String
Dim strbody As String

'for formatting reasons
strbody = "<html><body>"

'for looping
With Sheets("List").Select
lastrow = Cells(Rows.Count, "B").End(xlUp).Row
End With

For r = 2 To lastrow


Set OApp = CreateObject("Outlook.Application")
Set OMail = OApp.CreateItem(0)


'       Get the email address
Sheets("List").Select
Email = Cells(r, "K")

'       Message subject
    Sheets("List").Select
Subj = "Renewal for " & Cells(r, "B").Text & " Client # " & Cells(r, "A").Text & " Effective " & Cells(r, "D").Text

'       Message body
Sheets("List").Select
strbody = "<p>Dear " & Cells(r, "J").Text & ", </p>" & _
"I am contacting you regarding the upcoming renewal for " & Cells(r, "B").Text & ", account number " & Cells(r, "A").Text & ", which is effective " & Cells(r, "D").Text & ". We have reviewed the account and determined that we have the information we need on file in order to offer renewal terms. & _
"Should you have any questions or if we can be of futher assistance, please don't hesitate to contact " & Cells(r, "O").Text & " at " & Cells(r, "M").Text &                 " or " & Cells(r, "N").Text & _
" or respond to this email. If you are aware of changes to the contact on this account, please let us know, so we can be sure to get future correspondence to the proper person.<br><br>" & _
"As always, we would like to thank you for your business.<br><br>" & _
"Sincerely,"

On Error Resume Next

Sheets("List").Select
With OMail
.Display
.To = Email
.Subject = Subj
.HTMLBody = strbody & vbNewLine & .HTMLBody
End With
Next r

On Error GoTo 0


Set OMail = Nothing
Set OApp = Nothing

End Sub

2 个答案:

答案 0 :(得分:0)

所以这里有一些代码可以用两种方式处理你的问题。一种是限制批量...另一种是将mailobject保存在每个for循环的my documents文件夹中,将邮件对象设置为空。这应该让用户能够一次运行所有帐户,但在发送之前打开并编辑...这使我真正的解决方案。

找出这些用户正在编辑电子邮件的方案,然后为他们编写代码。此外,如果用户在发送之前手动查看每封电子邮件。也许完全摆脱循环并让他们在电子表格中想要下一个可用帐户时单击按钮。这可以通过在其上具有“已发送状态”的列来实现。

Option Explicit

Sub SendEMail()
Dim Email As String
Dim Subj As String
Dim Msg As String
Dim URL As String
Dim r As Integer
Dim x As Double
Dim OApp As Object
Dim OMail As Variant
Dim Signature As String
Dim strbody As String

'for formatting reasons
strbody = "<html><body>"

'for looping
With Sheets("List").Select
    lastrow = Cells(Rows.Count, "B").End(xlUp).Row
End With

For r = 2 To lastrow


    Set OApp = CreateObject("Outlook.Application")
    Set OMail = OApp.CreateItem(0)


'       Get the email address
    Sheets("List").Select
    Email = Cells(r, "K")

'       Message subject
    Sheets("List").Select
    Subj = "Renewal for " & Cells(r, "B").Text & " Client # " & Cells(r, "A").Text & " Effective " & Cells(r, "D").Text

'       Message body
    Sheets("List").Select
    strbody = "This was a syntax error, changing for simplicity."

    On Error Resume Next

    Sheets("List").Select
    With OMail
        .display
        .To = Email
        .Subject = Subj
        .HTMLBody = strbody & vbNewLine & .HTMLBody
''New
        .SaveAs ("C:\Users\" & Environ$("Username") & "\Documents\" &     Environ$("Username") & r & ".msg")
    End With
    Set OMail = Nothing
    Set OApp = Nothing

'''        'If you decide to limit your batches do it here
'''        If r = 62 Then
'''          MsgBox "Could do an assortment of things here...anyways, its     not a very good solution. "
'''        End If

    Next r

    On Error GoTo 0


    Set OMail = Nothing
    Set OApp = Nothing

End Sub

此外,这完全取决于您和您的业务需求。我真的会考虑将strbody从硬编码移到电子表格中的新工作表/文本文件或可用单元格中。使支持变得如此简单。

在阅读上面关于内存的评论之后..问题就是所有这些打开的电子邮件。您可能想要使用上面的save方法,然后编写一个新的宏,它将打开一个文件,其中包含从该目录修改的最早日期,点击发送后文件删除或存档...就像那样。

答案 1 :(得分:0)

我已经构建了一个类似的批处理工具并遇到了同样的问题,但发现它是不可预测的。寻找解决方案我决定限制脚本生成邮件的速度,每封邮件大约500毫秒 - 我的邮件带有多个附件,因此较小的邮件可能需要较少的限制。

我现在可以非常稳定地创建&gt;总共100封电子邮件(所有电子邮件合计),范围在200Mb到300Mb之间。

我觉得这是Excel / VBA和Outlook之间界面中的技术问题。

相关问题