vba 列出附件的文件名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11809782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 17:10:29  来源:igfitidea点击:

List the filenames of attachments

vbafilenamesattachmentoutlook-vba

提问by user1574359

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?

有没有办法在 msgbox 或组合框或任何东西中获取此文件的名称?

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

回答by JimmyPena

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