Solved

Copying messages from one folder to another

Posted on 2007-11-19
5
3,194 Views
Last Modified: 2010-04-21
I need some code to copy any email messages that I have highlighted to a specific folder.  I can find many code snippets for moving messages, but I don't want to move them I want to copy them.   I found this code from BlueDevil:  

Sub CopyMessages(strFolder As String)
    Dim olkItem As Object, _
        olkFolder As Outlook.MAPIFolder
    Set olkFolder = OpenMAPIFolder(strFolder)
    If TypeName(olkFolder) = "MAPIFolder" Then
        For Each olkItem In Application.ActiveExplorer.Selection
            olkItem.UnRead = False
            olkItem.Save
            olkItem.Move olkFolder
        Next
    End If
    Set olkFolder = Nothing
    Set olkItem = Nothing
End Sub


It seems as though this may be what I need except where it says "olkItem.Move olkFolder" I need the command for copying.  

This is my first foray into vba for outlook.  Yikes!

Thanks.  
0
Comment
Question by:shopsleep
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:MorDrakka
ID: 20314495
Hi,

I believe your answer is in here

http://www.experts-exchange.com/Microsoft/Applications/Q_22406876.html

Hope this helps!
0
 
LVL 6

Expert Comment

by:MorDrakka
ID: 20314505
Oops sry to fast, code you posted is in there sorry again.
0
 

Author Comment

by:shopsleep
ID: 20315592
Yes, that's the one I got the code I had in the first place.  It only moves it, not copies it. Thanks for trying though!
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 20322087
Hi, shopsleep.

This should do it.  You can't copy directly to another folder.  The Copy method makes a copy and then we have to use the Move method to get the copy to the other folder.

Sub CopyMessages(strFolder As String)
    Dim olkItem As Object, _
        olkCopy As Object, _
        olkFolder As Outlook.MAPIFolder
    Set olkFolder = OpenMAPIFolder(strFolder)
    If TypeName(olkFolder) = "MAPIFolder" Then
        For Each olkItem In Application.ActiveExplorer.Selection
            olkItem.UnRead = False
            olkItem.Save
            Set olkCopy = olkItem.Copy
            olkCopy.Move olkFolder
        Next
    End If
    Set olkFolder = Nothing
    Set olkItem = Nothing
    Set olkCopy = Nothing
End Sub
0
 

Author Closing Comment

by:shopsleep
ID: 31409987
Thank you, thank you, thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike scripting languages such as C# where a semi-colon is used to indicate the end of a command, Microsoft's VBScript language relies on line breaks to determine when a command begins and ends. As you can imagine, this quickly results in messy cod…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now