【发布时间】:2020-06-30 07:08:03
【问题描述】:
程序: Outlook 2010
操作系统: Win8
VBA 技能: 新手
要求
我有一个用于销售报告的 template.oft,我通过这个宏调用它。
该宏附加一个静态文件,其次是一个动态名称。
我想使用另一个变量来附加动态文件。
'Working File
Sub zzzAccs()
Dim newItem As Outlook.mailItem
Dim dateFormat As String
dateFormat = Format(Now, "YYYYMMDD")
Set newItem = CreateItemFromTemplate(":\location\zzz accs.oft")
newItem.Attachments.Add ":\location\" & "zzz sales_" & Format(Now, "YYYYMMDD") & ".pdf"
'Attachment 2 - always will have the same name, general notice/reminder
newItem.Attachments.Add ":\location\zzz Notice.pdf"
newItem.Display
End Sub
我想要什么 使用通配符调用文件。
总会有:
":\location\zzz Acc(通配符,即上个月内的日期).pdf"
这样,它总是会选择帐户文件,但日期或动态通配符的日期要么是当月,要么是其他日期。
例如: “:\location\zzz Acc 20140201.pdf”(当前月份,但不是定义的“从现在开始的日期”) “:\location\zzz Acc statement Feb 2014.pdf”(将根据文件的用途而改变)。
注意
此后我尝试了以下方法,但它只会附加 1 个文件,而不是所有带有通配符的文件:
'source: http://stackoverflow.com/a/13729215/2337102
Dim strPath As String
Dim strFilter As String
Dim strFile As String
strPath = "E:\My Documents\" 'Edit to your path
strName = "test_" 'added in file core name as I didn't want all the .pdf attached
strFilter = "*.pdf"
strFile = Dir(strPath & strName & strFilter)
'New email message from Template
Set newItem = CreateItemFromTemplate("E:location\test.oft")
'File Locations
newItem.Attachments.Add "E:\My Documents\" & "test - " & Format(Now, "YYYYMMDD") & ".pdf"
newItem.Attachments.Add "E:\My Documents\test.pdf"
newItem.Attachments.Add (strPath & strFile)
'the above line only attached 1 file, not 3 that were named according to the str Rules eg:
'test_2014; test_20140131; test_agreement
请指教。
【问题讨论】: