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
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