【问题标题】:List the filenames of attachments列出附件的文件名
【发布时间】:2012-08-04 15:28:43
【问题描述】:

在这次考试中,我在草稿数据中获得了一封电子邮件的“附件文件”的数量。

有没有办法在 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

【问题讨论】:

    标签: vba outlook filenames attachment


    【解决方案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
    

    【讨论】:

    • .DisplayName.FileName有什么区别?
    • @SysDragon DisplayName Returns or sets a String representing the name, which does not need to be the actual file name, displayed below the icon representing the embedded attachment. 文件名 Returns a String representing the file name of the attachment.
    猜你喜欢
    • 1970-01-01
    • 2012-06-22
    • 1970-01-01
    • 2014-10-19
    • 1970-01-01
    • 2012-05-22
    • 1970-01-01
    • 2019-02-27
    • 2019-10-05
    相关资源
    最近更新 更多