将具有不同日期的附件添加到Outlook邮件中

问题描述 投票:1回答:5

我有一个名为“计划用家庭音频(28-3-2013)的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
excel vba outlook-vba
5个回答
7
投票
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


1
投票
.Attachments.Add ("C:\Users\Desktop\Today\Home Audio for Planning (" & FORMAT(DATE,DD-MM-YYYY)")

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

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

欢呼声

0
投票
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

结束子


0
投票
如果没有,.BodyFormat = olFormatHTML文件将附加在邮件正文中
© www.soinside.com 2019 - 2024. All rights reserved.