【问题标题】:Save Outlook attached PDF to temp filder via Drag and Drop in VBA通过 VBA 中的拖放将 Outlook 附加的 PDF 保存到临时文件夹
【发布时间】:2019-12-10 07:08:27
【问题描述】:

我正在寻找一种方法将 PDF 文件从 Outlook 邮件保存到用户的 Temp 文件夹以使用它。

我在 C# 中做过一段时间,但似乎 VBA 无法处理 Outlook 文件的拖放操作。

所以我的 Excel 文件中有一个用户窗体。在这个表单中是一个 ListView。我可以从资源管理器中拖放文件,将文件的路径写入工作表。 所以我想对来自 Outlook 附件的 PDF 文件做同样的事情。但我找不到将 PDF 保存到文件夹的方法。

有没有办法通过 ListView 中的拖放事件来做到这一点?

【问题讨论】:

  • 什么是拖放?据我所知,这是一个人机界面的事情,在后台没有发生任何事情。在后台是复制或移动

标签: excel vba pdf outlook


【解决方案1】:

拖放会降低自动化质量。但是我之前使用过宏来检索带有附件的电子邮件。我把它给你希望对你有用

Sub GetAttachments()
Dim oMailItem As Outlook.MailItem
Dim oApp As Outlook.Application
Dim oMAPIFolder As Outlook.MAPIFolder
Dim oFolder As Outlook.Folder
Dim oNS As Outlook.Namespace
Dim iCnt As Integer, RowCnt As Integer
Dim DataSheet As Worksheet

Set oApp = New Outlook.Application
Set oNS = oApp.GetNamespace("MAPI")
Set oMailItem = oApp.CreateItem(0)
Set DataSheet = ActiveSheet
RowCnt = 2

For Each oFolder In oNS.GetDefaultFolder(olFolderInbox).Folders
    Set oMAPIFolder = oNS.GetDefaultFolder(olFolderInbox).Folders(oFolder.Name)
    For iCnt = 1 To oMAPIFolder.Items.Count
        '..... In this section you can put another if to check emails within special date condition.
        If TypeOf oMAPIFolder.Items(iCnt) Is MailItem Then
            '......... this message has attchment. you can check if it is pdf or not.
            Set oMailItem = oMAPIFolder.Items(iCnt)
            If oMailItem.Attachments.Count > 0 Then
                With DataSheet
                    .Cells(RowCnt, 2) = oMailItem.Subject
                    .Cells(RowCnt, 3) = oMailItem.Sender.Address
                    .Cells(RowCnt, 4) = oMailItem.ReceivedTime
                    .Cells(RowCnt, 1) = oMailItem.Attachments.Item(1).Filename
                    RowCnt = RowCnt + 1
                End With
            End If
        End If
    Next iCnt
Next

Set oApp = Nothing
Set oNS = Nothing
Set oMailItem = Nothing
Set oMAPIFolder = Nothing
Set oFolder = Nothing
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-01
    • 1970-01-01
    • 2021-11-14
    • 2019-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多