Solved

Copying messages from one folder to another

Posted on 2007-11-19
5
3,197 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

786 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