+ Reply to Thread
Results 1 to 4 of 4

Drag&drop outlook email to drop zone in excel

  1. #1
    Registered User
    Join Date
    09-03-2013
    Location
    poland
    MS-Off Ver
    Excel 2010
    Posts
    6

    Drag&drop outlook email to drop zone in excel

    Hi there, I was looking for solutions everywhere, however I did not find it. Maybe someone is able to help me.
    I used Treeview OLEdrogDrop to create a zone in excel sheet which let the user to drag any file and copy to defined location. This solution does not work for drag&drop of outlook emails. Excel returns run-time error 461. I would like to save emails in the same way too. Any ideas how to do it?

    Currently used code:

    Private Sub TreeView31_OLEDragDrop(Data As MSComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)

    Dim strPath As String

    strPath = Data.Files(1)


    Dim FSO As Object
    Dim FromPath As String
    Dim ToPath As String
    Dim FileExt As String


    FromPath = strPath
    ToPath = "V:\"

    FileExt = "*.*"
    'You can use *.* for all files or *.doc for Word files

    If Right(FromPath, 1) = "\" Then
    FromPath = Left(FromPath, Len(FromPath) - 1)
    End If

    If Right(ToPath, 1) = "\" Then
    ToPath = Left(ToPath, Len(ToPath) - 1)
    End If


    Set FSO = CreateObject("scripting.filesystemobject")

    If FSO.FileExists(FromPath) = False Then
    MsgBox FromPath & " doesn't exist"
    Exit Sub
    End If

    If FSO.FolderExists(ToPath) = False Then
    MsgBox ToPath & " doesn't exist"
    Exit Sub
    End If

    FSO.CopyFile Source:=FromPath & FileExt, Destination:=ToPath
    MsgBox "You can find the files from " & FromPath & " in " & ToPath
    End Sub

  2. #2
    Registered User
    Join Date
    09-03-2013
    Location
    poland
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Drag&drop outlook email to drop zone in excel

    I've found a code which may be useful in this situation, however it does not work due to early/late binding (I'm using Office 2010). Anyone has idea how to convert below code?

    Dim msg As MailItem
    Dim file As Attachment
    Dim loc As String
    Dim app As New Outlook.Application
    Dim exp As Outlook.Explorer
    Dim sel As Outlook.Selection
    Dim res As Boolean

    '-- enter location in which files will be copied
    loc = "C:\temp\"

    '-- find selected email(s) used in drag-drop
    Set exp = app.ActiveExplorer
    Set sel = exp.Selection

    '-- clear text field
    txtFiles.Text = ""

    '-- parse each selected email
    For Each msg In sel
    txtFiles.Text = txtFiles.Text & "[" & msg.SenderName & "] " & msg.ConversationTopic & " : " & vbCrLf
    If msg.Attachments.Count > 0 Then
    On Error GoTo failed
    For Each file In msg.Attachments
    res = True
    txtFiles.Text = txtFiles.Text & " - " & file.Filename
    file.SaveAsFile loc & file.Filename
    If res Then txtFiles.Text = txtFiles.Text & " [saved]" & vbCrLf
    Next file
    On Error GoTo 0
    Else
    txtFiles.Text = txtFiles.Text & " no attachments found." & vbCrLf
    End If
    Next msg
    Exit Sub

    failed:
    txtFiles.Text = txtFiles.Text & " [FAILED : " & Err.Description & "]" & vbCrLf
    res = False
    Resume Next

  3. #3
    Registered User
    Join Date
    09-03-2013
    Location
    poland
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Drag&drop outlook email to drop zone in excel

    Ok, no replies, but finally I found solution:

    Dim oMail As Outlook.MailItem
    Dim objItem As Object
    Dim sPath As String
    Dim dtDate As Date
    Dim sName As String
    Dim enviro As String
    Dim msg As MailItem
    Dim file As Attachment
    Dim loc As String
    Dim app As New Outlook.Application
    Dim exp As Outlook.Explorer
    Dim sel As Outlook.Selection
    Dim res As Boolean


    For Each objItem In ActiveExplorer.Selection
    Set oMail = objItem
    sName = oMail.Subject
    ReplaceCharsForFileName sName, "_"
    dtDate = oMail.ReceivedTime
    sName = Format(dtDate, "yyyymmdd", vbUseSystemDayOfWeek, _
    vbUseSystem) & Format(dtDate, "-hhnnss", _
    vbUseSystemDayOfWeek, vbUseSystem) & "-" & sName & ".msg"
    sPath = "V:\"
    Debug.Print sPath & sName
    oMail.SaveAs sPath & sName, olMSG
    Next
    End Sub
    Private Sub ReplaceCharsForFileName(sName As String, _
    sChr As String _
    )
    sName = Replace(sName, "/", sChr)
    sName = Replace(sName, "\", sChr)
    sName = Replace(sName, ":", sChr)
    sName = Replace(sName, "?", sChr)
    sName = Replace(sName, Chr(34), sChr)
    sName = Replace(sName, "<", sChr)
    sName = Replace(sName, ">", sChr)
    sName = Replace(sName, "|", sChr)
    End Sub

  4. #4
    Registered User
    Join Date
    09-03-2013
    Location
    poland
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Drag&drop outlook email to drop zone in excel

    ehh, unfortunately it's not a final solution. The main problem is when using above code I can copy (save) message only, does not matter whether I'm dragging msg or one of attachments.
    In my case user should be able to drag one of e-mail msg attachments and drop to 'drop zone' in excel sheet. Single (selected) file should be saved in defined location. Something like simple 'save as' but triggered by drag and drop.
    I've just explored internet - nil findings. Any ideas how to do it?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Create a dependent drop down for Outlook email
    By spiwere in forum Excel Programming / VBA / Macros
    Replies: 50
    Last Post: 04-30-2013, 04:00 PM
  2. drag and drop from Excel
    By MLC2 in forum Access Tables & Databases
    Replies: 3
    Last Post: 10-12-2012, 02:04 PM
  3. [SOLVED] Drag & Drop csv file into Excel
    By TimTDP in forum Excel General
    Replies: 21
    Last Post: 11-14-2011, 04:17 PM
  4. Excel drag & drop
    By daniel123 in forum Excel General
    Replies: 5
    Last Post: 11-10-2009, 05:43 PM
  5. Drag Drop in Excel
    By rahul.singh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-24-2005, 12:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1