Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Copy Emails from Outlook using a Excel VBA userform

Copy Emails from Outlook using a Excel VBA userform

Copy Emails from Outlook using a Excel VBA userform


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

RE: Copy Emails from Outlook using a Excel VBA userform


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


glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

RE: Copy Emails from Outlook using a Excel VBA userform

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?


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close