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

时间:2018-11-15 09:45:33

标签: vba excel-2016 ms-access-2016 outlook-2016

在Windows 7和Office 2007中,我一直在使用在Outlook中打开新电子邮件,附加文件并发送的代码。它不是我的代码,我在互联网上的某个地方找到了它。问题是,现在我使用Windows 10和Office 2016,并且使用相同的代码会产生不同的结果,如下所示:

  • 文件的原始名称(例如“ Products.xlsx”)更改为“ ProjectStatus.xlsx”(任何文件名始终更改为“ ProjectStatus.xlsx”)
  • 如果我打开文件,则Excel将其打开并显示文件的原始名称(“ Products.xlsx”)
  • 如果我发送它,则有时收件人将附件视为“ ProjectStatus.xlsx”,有时将其视为“ Products.xlsx”。但是总会发生的是,如果他们打开文件,在excel中会被视为“ Products.xlsx”

我需要始终使用原始名称显示文件名。我该怎么办?

这是我使用的代码,并且从access 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并不了解。

提前谢谢!

1 个答案:

答案 0 :(得分:1)

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

  

仅当邮件项目为RTF格式时,此参数才适用   并将“类型”设置为olByValue:名称显示在检查器中   附件的对象,或查看附件的属性时   附件。如果邮件项目为纯文本或HTML格式,则   使用Source参数中的文件名显示附件。

因此,如果您始终希望始终使用原始文件名,只需删除, "ProjectStatus"的实例即可。