首页 文章

VBA Excel从outlook拖放电子邮件

提问于
浏览
2

我在Excel中开发了一个表单,它正在向邮箱发送电子邮件 . 这部分工作正常 .

现在我正在寻找开发一个“后台”excel工作簿,这将允许:

将电子邮件从outlook拖放到Excel按钮

将此电子邮件保存到文件夹

阅读此电子邮件,并将所有部分(发件人的电子邮件,主题,正文,...)保存在Excel电子表格中 .

我正在尝试进行导入阶段(从outlook中拖放)但没有找到这样做的方法......

谢谢你的帮助

1 回答

  • 2

    你不能在按钮上放一个电子邮件(好吧,你可以......)而是创建一个编辑框(Outlookbox)并将其绑定到事件处理程序 . 这里有一些代码可以帮助您入门:

    Private Sub Outlookbox_Change()
        Dim olApp As Object    'Outlook.Application
        Dim olExp As Object    'Outlook.Explorer
        Dim olSel As Object    'Outlook.Selection
        Dim i As Integer
        Dim theSender as String
        Dim theDate as String
        Dim theRecipient as String
        Dim theSubject as String
        Dim theMessage as String
    
        Set olApp = GetObject("", "Outlook.Application")
        Set olExp = olApp.ActiveExplorer
        Set olSel = olExp.Selection
        For i = 1 To olSel.Count ' If multiple emails dropped
          With olSel.Item(i)     ' For each email
            theSender = .Sender
            theDate = .ReceivedTime
            theRecipient = .To
            theSubject = .Subject
            theMessage = .Body
          End With
        Next i
    End Sub
    

相关问题