Solved

Copying messages from one folder to another

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Welcome to part one of a multi-part tutorial series, VBScript for Windows System Administrators.  The goal of this series is to teach non-programmers how to write useful VBS code to automate their environment, and perform tasks faster, and in a more…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 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

17 Experts available now in Live!

Get 1:1 Help Now