2012-08-04 22 views
1

在本次考試中,我將獲取草稿數據中電子郵件的「附件」的編號。列出附件的文件名

有沒有什麼辦法讓這個文件的名稱在msgbox或combobox或任何東西?

Private Sub CommandButton2_Click() 

Dim a As Attachments 
Dim myitem As Folder 
Dim myitem1 As MailItem 

Set myitem = Session.GetDefaultFolder(olFolderDrafts) 

Dim i As Integer 

For i = 1 To myitem.Items.Count 

If myitem.Items(i) = test1 Then 

Set myitem1 = myitem.Items(i) 

Set a = myitem1.Attachments 

MsgBox a.Count 

End If 
Next 

End Sub 

回答

3
Private Sub CommandButton2_Click() 

Dim a As Attachments 
Dim myitem As Folder 
Dim myitem1 As MailItem 
Dim j As Long 
Dim i As Integer 

Set myitem = Session.GetDefaultFolder(olFolderDrafts) 

For i = 1 To myitem.Items.Count 
    If myitem.Items(i) = test1 Then 
    Set myitem1 = myitem.Items(i) 
    Set a = myitem1.Attachments 

    MsgBox a.Count 

    ' added this code 
    For j = 1 To myitem1.Attachments.Count 
     MsgBox myitem1.Attachments.Item(i).DisplayName ' or .Filename 
    Next j 

    End If 
Next i 
End Sub 
+0

是什麼'.DisplayName'和'.FileName'之間的區別? – SysDragon 2013-05-10 05:30:22

+2

@SysDragon DisplayName'返回或設置一個表示名稱的字符串,該名稱不必是實際的文件名,顯示在代表嵌入式附件的圖標下.'文件名'返回表示附件的文件名的字符串。 – JimmyPena 2013-05-11 01:18:09