List the filenames of attachments

怎甘沉沦 提交于 2019-12-01 08:25:44

问题


In this exam I get the number of "attachment file" for an email in draft data.

Is there any way to get the name of this file in a msgbox or combobox or anything?

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

回答1:


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


来源:https://stackoverflow.com/questions/11809782/list-the-filenames-of-attachments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!