Drag and drop emails into vba userform

Gillettos

New Member
Joined
Apr 12, 2019
Messages
1
Hi,

I'm looking for some help, I want to ultimately create an area where I can drag emails into a window within a user form, and then they get automatically copied to a specified directory.

I have been trying for days and searched the web but fail every time. I have the following using listview:

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

I found this which one guys claims in works, and there many similar to the one below also but don't work either.

The problem I get is when it gets to the SaveAs part, as an Run-time 287 - Application-defined or object-defined error occurs....

I have enabled all the references within VBA.

Any help would be much appreciated :)


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 = "Y:"
Debug.Print sPath & sName
' oMail.Copy sPath & sName, olMSG
oMail.SaveAs sPath & sName, olMSG
Next
End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,224,820
Messages
6,181,154
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top