简体   繁体   中英

VBA Excel drag and drop email from outlook

I have developed a form in excel, which is sending an email to a mailbox. This part is working fine.

Now i'm looking to develop an "back-office" excel workbook Which would allow to :

Drag and drop email from outlook to an excel button

Save this email to a folder

Reading this email, and saving all parts (sender's email, subject, body, ...) in an excel spreadsheet.

I'm trying to do the import phase (drag and drop from outlook) but didn't find the way to do this...

Thanks for your help

You cannot drop an email on a button (well, you can but ...) Instead create an editbox (Outlookbox) and tie it to an event handler. Here's some code to get you started:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM