在发送'发送'之后将Outlook电子邮件(.msg)的副本保存到文件夹被压了

时间:2015-09-23 05:13:07

标签: vba email outlook-vba

我已经尝试了下面的代码,它的工作方式完全符合我的要求。 http://www.mrexcel.com/forum/excel-questions/361751-visual-basic-applications-saving-email-only-after-send-pushed.html

但是,当我为使用不同Excel版本的其他同事创建此文件时,我的一些同事出现了库错误。阅读后,我相信我需要使用后期绑定而不是早期绑定,因此具有不同excel版本的人可以访问该功能。

如何更改下面的代码(到后期绑定)以便所有其他版本的excel用户也可以使用该功能?下面是工作代码的副本。

班级代码

Option Explicit
Public WithEvents obj_OL As Outlook.Application
'
Private Sub obj_OL_ItemSend(ByVal Item As Object, Cancel As Boolean)

    '// For example, change pathway to suit, such as:                           //
    '// "\\Dacsrv02\rtddata\Advice\TechQueries\TRIM Emails\" & emailname
    OutMail.SaveAs ThisWorkbook.Path & _
                           Application.PathSeparator & _
                           emailname

    '// AFTER the event has been called, explicitly release Outlook.        //
    Set obj_OL = Nothing
    Set OutMail = Nothing
End Sub

子代码

Option Explicit
'// Connect the declared object w/the class module                          //
Dim cls_OL As New clsOutlook
'// Declare the email msg (mail item) and emailname string as Public, so    //
'// that they can be "seen" from any procedures in the class mod.           //
Public OutMail As Outlook.MailItem
Public emailname As String

Sub Email_Response()
Dim strbody As String

    '// Create our new mail item                                            //
    Set OutMail = cls_OL.obj_OL.CreateItem(0)

    '// Example substitute                                                      //
    strbody = "This is just example text"

    On Error Resume Next

    emailname = "something.msg"

    With OutMail
        .To = ""
        .CC = ""
        .BCC = ""
        .Subject = "Specific Subject"
        .body = strbody
        .Display
    End With

    On Error GoTo 0

End Sub

1 个答案:

答案 0 :(得分:0)

您不能(轻松)使用后期绑定支持事件,而不是VB脚本。无论谁使用您的代码,都需要将正确版本的Outlook添加到项目引用中。