Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy Emails from Outlook using a Excel VBA userform

Status
Not open for further replies.

gillettos

Programmer
Apr 11, 2019
2
GB
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
 
Hi,

Where in your code do you instantiate olMSG or assign an object?

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
 
Thanks for the reply skipvought :0)

Im a newbee to this and do a alot of learning of the web.

I don't think i do, in answer to your question, how and where do i do this?

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top