2014-10-20 29 views
0

我試圖修改宏以保存今天到達的電子郵件中的所有附件。問題是我不知道如何引用Outlook VBA中的電子郵件對象的日期屬性。Outlook 2010 VBA保存某些日期的附件

我該怎麼做,更重要的是我該如何找到下一次如何引用對象?我沒有找到很多有關Outlook對象模型的參考資料。

我現有的代碼如下:

Sub GetAllAttachments() 'Exports and saves all attachements in the inbox 

Dim ns As NameSpace 
Dim Inbox As MAPIFolder 
Dim Item As Object 
Dim Atmt As Attachment 
Dim FileName As String 
Dim i As Integer 

Today = Format(Now(), "yyyy MM dd") 

Set ns = GetNamespace("MAPI") 
Set Inbox = ns.Folders("Secondary") 
Set Inbox = Inbox.Folders("Inbox") 

i = 0 

If Inbox.Items.Count = 0 Then 
    MsgBox "There are no messages in the Inbox.", vbInformation, _ 
      "Nothing Found" 
    Exit Sub 
End If 

For Each Item In Inbox.Items 
    If EMAIL_DATE = Today Then 
     For Each Atmt In Item.Attachments 
        FileName = "C:\Email Attachments\" & Atmt.FileName 
        Atmt.SaveAsFile FileName 
        i = i + 1 
     End If 
    Next Atmt 
Next Item 

End Sub 

回答

0

項目沒有日期屬性。

嘗試使用

Outlook.MailItem 

例如:

Dim oMI as Outlook.MailItem 

For Each oMI in Application.ActiveExplorer.Selection 
    Msgbox (oMI.RecievedTime) 
Next 

您需要剝離從時間日期。

+0

好的,讓我來解決這個問題,看看它是怎麼回事。 – timbram 2014-10-21 15:27:25

+0

它一直抱怨對象不支持這種方法。 – timbram 2014-10-21 15:51:55

+0

給定「Dim oMI as Outlook.MailItem」,您只能選擇郵件項目。 – niton 2014-10-25 13:25:21