我的附件丢失了原来的名称,显示为 ProjectStatus.xlsx

My attachments lose their original name and are show as ProjectStatus.xlsx

在 windows 7 和 Office 2007 中,我一直在使用一种代码,它可以在 Outlook 中打开一封新电子邮件,附加一个文件并发送。代码不是我的,是在网上找的。问题是现在我使用 Windows 10 和 Office 2016,使用相同的代码会产生不同的结果:

我需要文件名始终以原始名称显示。我该怎么做?

这是我使用的代码,从访问 2016 和 excel 2016 执行。

Sub MandaMailA(destinatarios As String, copia As String, subject As String, strbody As String, attachment1 As String, Optional attachment2 As String = "", Optional CO As String = "")

    Dim OutApp As Object
    Dim OutMail As Object
    Dim SigString As String
    Dim Signature As String

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)



    'Change only Mysig.htm to the name of your signature
    SigString = Environ("appdata") & _
                "\Microsoft\Firmas\VBA.htm"

    If Dir(SigString) <> "" Then
        Signature = GetBoiler(SigString)
    Else
        Signature = ""
    End If

    On Error Resume Next

    With OutMail
        .To = destinatarios
        .CC = copia
        .BCC = CO
        .subject = subject
        .HTMLBody = strbody & "<br>" & Signature
        .Display    'or use .Display
        .Attachments.Add attachment1, olByValue, 1, "ProjectStatus"
        .Attachments.Add attachment2, olByValue, 1, "ProjectStatus"

    End With

    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

我注意到此代码包含 "ProjectStatus" 一词,但老实说我对 VBA 了解不深。

提前致谢!!

您只需要简单阅读 Attachments.Add 文档,特别是有关可选 DisplayName 参数的部分:

This parameter applies only if the mail item is in Rich Text format and Type is set to olByValue : the name is displayed in an Inspector object for the attachment or when viewing the properties of the attachment. If the mail item is in Plain Text or HTML format, then the attachment is displayed using the file name in the Source parameter.

因此,如果您始终希望始终使用原始文件名,只需删除 , "ProjectStatus".

的实例即可