Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Copying messages from one folder to another

Posted on 2007-11-19
5
Medium Priority
?
3,221 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

660 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