将电子邮件附件文件名列表复制到剪贴板

我收到带有1到30多个附件的电子邮件。我需要在我们的订单系统中重新输入他们的名字。

我想获取所有附件的列表,仅列出文件名,然后将其显示在消息框中,以便我可以将其复制或直接放在剪贴板上。我已经在网上搜索并找到了所需的零配件,但是我不能完全将它们组合在一起。

这是我到目前为止的内容,但是它一次循环遍历列表1,这无济于事。

BACKUP DATABASE MyDatabase TO DISK = @DIFFERENTIALBackupPath  WITH DIFFERENTIAL
BACKUP LOG MyDatabase TO  DISK = @DIFFERENTIALBackupPath

这是我尝试过的另一个,但是只是将名字放在剪贴板上:

Sub ListAttachments()
Dim a As Attachments
Dim myitem1 As Outlook.mailItem
Dim j As Long

Set myitem1 = activeExplorer().Selection.item(1)
Set a = myitem1.Attachments

For j = 1 To myitem1.Attachments.Count
    MsgBox myitem1.Attachments.item(j).DisplayName ' or .Filename
Next j

End Sub

谢谢。

cj1987fdsgsg 回答:将电子邮件附件文件名列表复制到剪贴板

debug.print给了我一个主意!我最终得到了以下内容,将其复制到剪贴板并放入了消息框中。谢谢托尼。

Sub ListAttachments()

'declare somethings
Dim a As Attachments
Dim myitem1 As Outlook.mailItem
Dim j As Long
Dim myText As String
Set myitem1 = ActiveExplorer().Selection.item(1)
Set a = myitem1.Attachments

'this isn't needed but it makes it look nicer
myText = "Files:" & vbLf

'cycles through each attachment,including images in the email,'and adds them to the 'myText' with a line break after each
For j = 1 To myitem1.Attachments.Count
    myText = myText & vbLf & myitem1.Attachments.item(j).DisplayName ' or .Filename
Next j

'These four lines are only needed for copying to the clipboard,but they require FM20.dll be 'on'
'they can be removed if you don't want to enable fm20.dll or if the message box is fine.
'remember,in windows,you can press ctrl+c to copy the text in a message box
Dim Buf As MSForms.DataObject
Set Buf = New MSForms.DataObject
Buf.SetText myText
Buf.PutInClipboard

'displays the final message box that I can copy and use elsewhere.
MsgBox myText

End Sub
本文链接:https://www.f2er.com/2890751.html

大家都在问