我正在Outlook 2013中编写一个VBA脚本,用于保存传入的附件 电子邮件。 我有这个工作正常,但我想通过文件扩展名过滤,只保存,例如,.FOO文件。
我认为将文件名保存为字符串很简单:
Dim nameString As String
nameString = oAttachment.DisplayName
但 nameString = oAttachment.DisplayName 会引发错误:" 无效的限定符"
答案 0 :(得分:2)
而不是DisplayName
查看FileName
。
我使用的代码类似于:
Sub Test_ItemAdd(ByVal Item As Object)
'when a new item is added to our "watched folder" we can process it
Dim olAtt As Attachment
Dim i As Integer
Dim objFSO As Object
Dim sExt As String
If Item.Attachments.Count > 0 Then
Set objFSO = CreateObject("Scripting.FileSystemObject")
For i = 1 To Item.Attachments.Count
Set olAtt = Item.Attachments(i)
sExt = objFSO.GetExtensionName(olAtt.FileName)
If Left(sExt, 3) = "xls" Then
ElseIf sExt = "CSV" Then
End If
olAtt.SaveAsFile FILE_PATH & FILE_NAME
Item.UnRead = False
DoEvents
Next
End If
Set olAtt = Nothing
End Sub