gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 21:10:39 26 4
gpt4 key购买 nike

我有一个名为“用于规划的家庭音频(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

最佳答案

试试下面的代码: strLocation 将动态生成。您可以将此变量传递给您的附件。生成的文件名类似于 家庭音响规划_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

关于excel - 将文件名中具有不同日期的附件添加到 Outlook 邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15675414/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com