1
votes

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

1
Instead of a Drag&Drop feature, why not simply get excel's vba to gather all the emails and save them however you want?Xabier

1 Answers

2
votes

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