Solved

Copying messages from one folder to another

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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