1

我有一个名为“用于规划的家庭音频(2013 年 3 月 28 日)的 Excel 文件。

日期每天都会改变,但文字是一样的。

如何将这些文件附加到 Outlook?

Sub Test()

    Dim OutApp As Object
    Dim OutMail As Object
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    With OutMail
        .To = ""
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .Body = "Hello World!"

        .Attachments.Add ("C:\Users\Desktop\Today\Home Audio for Planning   (28-3-2013).xlsx")

        .Display
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With

End Sub
4

5 回答 5

7

试试下面的代码: strLocation 将动态生成。您可以将此变量传递给您的附件。生成的文件名类似于Planning_28-03-2013.xlsx 的家庭音频

Sub Test()
    Dim strLocation As String

    Dim OutApp As Object
    Dim OutMail As Object
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    With OutMail
        .To = ""
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .Body = "Hello World!"

        strLocation = "C:\Users\Desktop\Today\Home Audio for Planning" & Format(Now(), "_DD-MM-YYYY") & ".xlsx"
        .Attachments.Add (strLocation)
        .Display
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With

End Sub
于 2013-03-28T06:53:00.187 回答
1

简单的,

  .Attachments.Add ("C:\Users\Desktop\Today\Home Audio for Planning (" & FORMAT(DATE,DD-MM-YYYY)") 
于 2014-10-22T11:56:57.600 回答
0

您是否尝试更改附件名称动态。例如;

.Attachments.Add ("C:\Users\Desktop\Today\Home Audio for Planning   (" + timeVariable  + ").xlsx")

并且您可以在之前设置时间变量以匹配所需格式的日期。

干杯

于 2013-03-28T06:22:20.137 回答
0

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

Dim strSubject As String
Dim StrSub As Integer
Dim AttachCnt As Integer


AttachCnt = Item.Attachments.Count
strSubject = Item.Subject
StrSub = Len(strSubject)
strBody = Item.Body
strBod = InStr(1, UCase(strBody), "ATTACH")
cnsolidateMsg = ""

If strBod <> 0 And AttachCnt = 0 Then
        cnsolidateMsg = cnsolidateMsg & "Attachment is Null." & vbNewLine
End If

If StrSub = 0 Then
    cnsolidateMsg = cnsolidateMsg & "Subject is Empty." & vbNewLine
End If
If UCase(Trim(strSubject)) = "FW:" Then
    cnsolidateMsg = cnsolidateMsg & "Forward mail subject is empty." & vbNewLine
End If
If UCase(Trim(strSubject)) = "RE:" Then
    cnsolidateMsg = cnsolidateMsg & "Reply mail subject is empty." & vbNewLine
End If

If cnsolidateMsg <> Empty Then
    If MsgBox(cnsolidateMsg & vbNewLine & "Are you sure you want to send the Mail?", vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for send mail") = vbNo Then
        Cancel = True
    End If
End If

结束子

于 2018-03-15T14:01:37.010 回答
0
With OutMail
    .To = ""
    .BodyFormat = olFormatHTML  '---Default
    .Attachments.Add ("C:\Users\Desktop\Test.txt")
    .Display
End With

如果不是.BodyFormat = olFormatHTML文件将附加在邮件正文中

于 2019-09-12T08:54:57.477 回答