copy an email and paste to another folder (3 Viewers)

smiler44

Registered User.
Local time
Today, 07:38
Joined
Jul 15, 2008
Messages
641
I have a macro that can move an email from one folder to another.
This is fine but i need two other people to get a copy of the email. all 3 people have a folder off of the group email inbox.

All emails go to inbox. they get checked and are moved to john or james or paul as required

inbox
john
james
paul

I can move from the inbox to any one of the other folders but how do i make a copy of the email and paste it to the other 2 peoples boxes. i cannot forward the email as that wont work, i have to copy it and paste it.

thanks

smiler44
 

sneuberg

AWF VIP
Local time
Yesterday, 23:38
Joined
Oct 17, 2014
Messages
3,506
If this is Outlook I see that if you right click on an item and move the cursor to Move there is a Copy to Folder action which seems to do what you want.
 

smiler44

Registered User.
Local time
Today, 07:38
Joined
Jul 15, 2008
Messages
641
I dont get the chance to copy a single email, i get the chance to copy the whole folder.

smiler44
 

sneuberg

AWF VIP
Local time
Yesterday, 23:38
Joined
Oct 17, 2014
Messages
3,506
If you want to copy all of the emails in the folder to another folder just select them all (Ctrl A) and then use Copy to Folder.

I'll try to write a macro for you if you are willing to wait for it. I've haven't written any for Outlook before but I suppose I should learn it. Do you want me to give this a try or can you do that part.

Don't you wish Microsoft made a macro recorder for Outlook?

Oh and if you mean you need to copy the folder rather than the contents you can right click on any folder to copy it to another folder.
 
Last edited:

Gasman

Enthusiastic Amateur
Local time
Today, 07:38
Joined
Sep 21, 2011
Messages
14,299
If you want to copy all of the emails in the folder to another folder just select them all (Ctrl A) and then use Copy to Folder.

I'll try to write a macro for you if you are willing to wait for it. I've haven't written any for Outlook before but I suppose I should learn it. Do you want me to give this a try or can you do that part.

Don't you wish Microsoft made a macro recorder for Outlook?

Oh and if you mean you need to copy the folder rather than the contents you can right click on any folder to copy it to another folder.

Here is something I amended from some code I found. perhaps it will give you a head start? It saves all attachments from selected emails to a folder.

Code:
Public Sub ReplaceAttachmentsToLink()
Dim objApp As Outlook.Application
Dim aMail As Outlook.MailItem 'Object
Dim oAttachments As Outlook.Attachments
Dim oSelection As Outlook.Selection
Dim i As Long
Dim iCount As Long
Dim sFile As String
Dim sFolderPath As String
Dim sDeletedFiles As String
Dim sDate As String, sTime As String
  
    ' Get the path to your My Documents folder
    sFolderPath = CreateObject("WScript.Shell").SpecialFolders(16)
    On Error Resume Next
  
    ' Instantiate an Outlook Application object.
    Set objApp = CreateObject("Outlook.Application")
  
    ' Get the collection of selected objects.
    Set oSelection = objApp.ActiveExplorer.Selection
  
    ' Set the Attachment folder.
    sFolderPath = sFolderPath & "\OLAttachments"
  
    'If folder does not exist create it
    If Dir(sFolderPath, vbDirectory) = "" Then
        MkDir sFolderPath
    End If
    
    ' Check each selected item for attachments. If attachments exist,
    ' save them to the Temp folder and strip them from the item.
    For Each aMail In oSelection
  
    ' This code only strips attachments from mail items.
    ' If aMail.class=olMail Then
    ' Get the Attachments collection of the item.
    Set oAttachments = aMail.Attachments
    iCount = oAttachments.Count
      
        
    If iCount > 0 Then
      
        ' We need to use a count down loop for removing items
        ' from a collection. Otherwise, the loop counter gets
        ' confused and only every other item is removed.
          
        For i = iCount To 1 Step -1
          
            ' Save attachment before deleting from item.
            ' Get the file name.
            sFile = oAttachments.Item(i).FileName
            
            'Now get Date & Time as strings to use in filename
            sDate = Format(Now(), "yyyymmdd")
            sTime = Format(Now(), "hhmmss")
              
            ' Combine with the path to the Temp folder.
            sFile = sFolderPath & "\" & sDate & "_" & sTime & "_" & sFile
              
            ' Save the attachment as a file.
            oAttachments.Item(i).SaveAsFile sFile
              
            ' Delete the attachment.
            oAttachments.Item(i).Delete
              
            'write the save as path to a string to add to the message
            'check for html and use html tags in link
            If aMail.BodyFormat <> olFormatHTML Then
                sDeletedFiles = sDeletedFiles & vbCrLf & "<file://" & sFile & ">"
            Else
                sDeletedFiles = sDeletedFiles & "<br>" & "<a href='file://" & _
                sFile & "'>" & sFile & "</a>"
            End If
              
                          
        Next i
        'End If
              
       ' Adds the filename string to the message body and save it
       ' Check for HTML body
       If aMail.BodyFormat <> olFormatHTML Then
           aMail.Body = aMail.Body & vbCrLf & _
           "The file(s) were saved to " & sDeletedFiles
       Else
           aMail.HTMLBody = aMail.HTMLBody & "<p>" & _
           "The file(s) were saved to " & sDeletedFiles & "</p>"
       End If
        
       aMail.Save
       'sets the attachment path to nothing before it moves on to the next message.
       sDeletedFiles = ""
     
       End If
    Next 'end aMail
      
ExitSub:
  
Set oAttachments = Nothing
Set aMail = Nothing
Set oSelection = Nothing
Set objApp = Nothing
End Sub
 

smiler44

Registered User.
Local time
Today, 07:38
Joined
Jul 15, 2008
Messages
641
If you want to copy all of the emails in the folder to another folder just select them all (Ctrl A) and then use Copy to Folder.

I'll try to write a macro for you if you are willing to wait for it. I've haven't written any for Outlook before but I suppose I should learn it. Do you want me to give this a try or can you do that part.

Don't you wish Microsoft made a macro recorder for Outlook?

Oh and if you mean you need to copy the folder rather than the contents you can right click on any folder to copy it to another folder.

sneuberg,
that is very kind of you. if you hare happy to have a go i would appreciate it and i too will have a go. your tip of ctrl A is a head start for me. I wont want to select them all just ones that i select. with the code i have and your tip i may be able to get it but i wont turn down the offer of help.

thank you

smiler44
 

smiler44

Registered User.
Local time
Today, 07:38
Joined
Jul 15, 2008
Messages
641
I fond this code on the internet but cant make it work.
Do I need to add any references?


Set objNS = Application.GetNamespace("MAPI") this gives a runtime error 438 object doesnt support this property or method





Code:
 [SIZE=3][FONT=Calibri]Sub MoveCopyMessage()[/FONT][/SIZE]
 [FONT=Calibri][SIZE=3] [/SIZE][/FONT]
 [SIZE=3][FONT=Calibri]    Dim objNS As Outlook.NameSpace[/FONT][/SIZE]
 [SIZE=3][FONT=Calibri]    Dim objSourceFolder As Outlook.MAPIFolder[/FONT][/SIZE]
 [SIZE=3][FONT=Calibri]    Dim objDestFolder As Outlook.MAPIFolder[/FONT][/SIZE]
 [SIZE=3][FONT=Calibri]    Dim objItem As Outlook.MailItem[/FONT][/SIZE]
 [SIZE=3][FONT=Calibri]    Dim objCopy As Outlook.MailItem[/FONT][/SIZE]
 [SIZE=3][FONT=Calibri]    [/FONT][/SIZE]
 [SIZE=3][FONT=Calibri]    Set objNS = Application.GetNamespace("MAPI")[/FONT][/SIZE]
 [FONT=Calibri][SIZE=3] [/SIZE][/FONT]
 [SIZE=3][FONT=Calibri]' Set the source and destination folders   [/FONT][/SIZE]
 [FONT=Calibri][SIZE=3]    Set objSourceFolder = objNS.Folders("Public Folders - [/SIZE][/FONT][EMAIL="alias@domain.com"][FONT=Calibri][SIZE=3][COLOR=#0000ff]alias@domain.com[/COLOR][/SIZE][/FONT][/EMAIL][SIZE=3][FONT=Calibri]") _[/FONT][/SIZE]
 [SIZE=3][FONT=Calibri]         .Folders("All Public Folders").Folders("New")[/FONT][/SIZE]
 [FONT=Calibri][SIZE=3]    Set objDestFolder = objNS.Folders("Public Folders - [/SIZE][/FONT][EMAIL="alias@domain.com"][FONT=Calibri][SIZE=3][COLOR=#0000ff]alias@domain.com[/COLOR][/SIZE][/FONT][/EMAIL][SIZE=3][FONT=Calibri]") _[/FONT][/SIZE]
 [SIZE=3][FONT=Calibri]         .Folders("All Public Folders").Folders("Old")[/FONT][/SIZE]
 [FONT=Calibri][SIZE=3] [/SIZE][/FONT]
 [SIZE=3][FONT=Calibri]    Set objItem = Application.ActiveExplorer.Selection.Item(1)[/FONT][/SIZE]
 [SIZE=3][FONT=Calibri]        [/FONT][/SIZE]
 [SIZE=3][FONT=Calibri] ' copy and move first [/FONT][/SIZE]
 [SIZE=3][FONT=Calibri]     Set objCopy = objItem.Copy[/FONT][/SIZE]
 [SIZE=3][FONT=Calibri]      objCopy.Move objDestFolder[/FONT][/SIZE]
 [SIZE=3][FONT=Calibri]        [/FONT][/SIZE]
 [SIZE=3][FONT=Calibri]' then do whatever[/FONT][/SIZE]
 [SIZE=3][FONT=Calibri]        With objItem[/FONT][/SIZE]
 [SIZE=3][FONT=Calibri]            .UnRead = False[/FONT][/SIZE]
 [SIZE=3][FONT=Calibri]            .MarkAsTask olMarkComplete[/FONT][/SIZE]
 [SIZE=3][FONT=Calibri]            .Categories = "This Category"[/FONT][/SIZE]
 [SIZE=3][FONT=Calibri]            .Save[/FONT][/SIZE]
 [SIZE=3][FONT=Calibri]        End With[/FONT][/SIZE]
 [SIZE=3][FONT=Calibri]        [/FONT][/SIZE]
 [SIZE=3][FONT=Calibri]    Set objSourceFolder = Nothing[/FONT][/SIZE]
 [SIZE=3][FONT=Calibri]    Set objDestFolder = Nothing[/FONT][/SIZE]
 [SIZE=3][FONT=Calibri]    Set objNS = Nothing[/FONT][/SIZE]
 [FONT=Calibri][SIZE=3]End Sub[/SIZE][/FONT]
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:38
Joined
May 7, 2009
Messages
19,243
the code will run inside Outlook. If you want to run it within Access you have to modify it.
Code:
Sub MoveCopyMessage()
 
     Dim objOutlook As Outlook.Application
     Dim objNS As Outlook.NameSpace
     Dim objSourceFolder As Outlook.MAPIFolder
     Dim objDestFolder As Outlook.MAPIFolder
     Dim objItem As Outlook.MailItem
     Dim objCopy As Outlook.MailItem
 
     Set objOutlook = New Outlook.Application
     Set objNS = objOutlook.GetNamespace("MAPI")
 
 ' Set the source and destination folders
     Set objSourceFolder = objNS.Folders("Public Folders - alias@domain.com") _
          .Folders("All Public Folders").Folders("New")
     Set objDestFolder = objNS.Folders("Public Folders - alias@domain.com") _
          .Folders("All Public Folders").Folders("Old")
 
     Set objItem = objOutlook.ActiveExplorer.Selection.Item(1)
 
  ' copy and move first
      Set objCopy = objItem.Copy
       objCopy.Move objDestFolder
 
 ' then do whatever
         With objItem
             .UnRead = False
             .MarkAsTask olMarkComplete
             .Categories = "This Category"
             .Save
         End With
 
     Set objSourceFolder = Nothing
     Set objDestFolder = Nothing
     Set objNS = Nothing
     Set objOutlook = Nothing
 End Sub
 

sneuberg

AWF VIP
Local time
Yesterday, 23:38
Joined
Oct 17, 2014
Messages
3,506
I fond this code on the internet but cant make it work.
Do I need to add any references?


Set objNS = Application.GetNamespace("MAPI") this gives a runtime error 438 object doesnt support this property or method

My understanding was that you want the macro for Outlook. Is this true? If you put this code in an Outlook module it shouldn't give you that error. When I tried it, it of course complained because I didn't have the folders named in that code (got object not found error) but when I change the folders name to names in my Outlook folder names it worked fine. The only thing is that it only copies the first item, not all of them in the folder. I'm still trying to figure out how to do that but thanks for posting the code as it's a start.
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:38
Joined
Sep 21, 2011
Messages
14,299
My understanding was that you want the macro for Outlook. Is this true? If you put this code in an Outlook module it shouldn't give you that error. When I tried it, it of course complained because I didn't have the folders named in that code (got object not found error) but when I change the folders name to names in my Outlook folder names it worked fine. The only thing is that it only copies the first item, not all of them in the folder. I'm still trying to figure out how to do that but thanks for posting the code as it's a start.

The items to be processed currently need to be selected in the code that I posted as that is how I wanted it to work.

You could combine with the code here
http://www.slipstick.com/developer/code-samples/working-items-folder-selected-items/

to process all items?
 

sneuberg

AWF VIP
Local time
Yesterday, 23:38
Joined
Oct 17, 2014
Messages
3,506
Here's an update on what I got so far and the problem I'm having.

Mainly from the code that was posted in this thread (My thanks to all) I created the following function that copies the contents of a SourceFolder to a DestinationFolder.

Code:
Private Function CopyAllItems(ByRef SourceFolder As Outlook.MAPIFolder, ByRef DestinationFolder As Outlook.MAPIFolder) As Long

Dim Count As Long
Dim Item As Outlook.MailItem
Dim Copy As Outlook.MailItem

Count = 0
For Each Item In SourceFolder.Items
    If Not [COLOR="royalblue"]HasDuplicate[/COLOR](DestinationFolder, Item) Then
        Set Copy = Item.Copy
        Copy.Move DestinationFolder
        Count = Count + 1
    End If
Next Item
CopyAllItems = Count
Set Copy = Nothing

End Function


I've tested this function with the following subroutine and it works exception for HasDuplicate function in it that needs work.

Code:
Sub Test1()
[COLOR="RoyalBlue"][/COLOR]
Dim objNS As Outlook.NameSpace
Dim objSourceFolder As Outlook.MAPIFolder
Dim objDestFolder As Outlook.MAPIFolder
Dim Count As Long
Set objNS = Application.GetNamespace("MAPI")

Set objSourceFolder = objNS.Folders("Personal Folders") _
.Folders("Inbox")
Set objDestFolder = objNS.Folders("Personal Folders") _
.Folders("Bobs")

Count = CopyAllItems(objSourceFolder, objDestFolder)
MsgBox Count & " items have been copied"

Set objNS = Nothing
Set objSourceFolder = Nothing
Set objDestFolder = Nothing

End Sub

Without something to check for duplicates the macro would copy the same emails if is run more than once. The question is what criteria to use to determine if a email is a duplicate. I think it would be sufficient to check the Subject and the Date/Time received. Please let me know if you agree with this or not. I've got the follow function to flag mails with the same subject but when I add the RECEIVED field it doesn't find the duplicates. So fixing that is where I'm at. I also want to try create a main program that will run in Outlook or Access.

Code:
Private Function HasDuplicate(ByRef SearchFolder As Outlook.MAPIFolder, ByRef Item As Outlook.MailItem) As Boolean

Dim Duplicate As Outlook.MailItem

If Item.Class <> olMail Then    'Duplication is not check for non mail items
    HasDuplicate = False
    Exit Function
End If

'Debug.Print "[Subject] = '" & ESQ(Item.Subject) & "' And [RECEIVED] = #" & Item.ReceivedTime & "#"
'Set Duplicate = SearchFolder.Items.Find("[Subject] = '" & ESQ(Item.Subject) & "' And [RECEIVED] = #" & Item.ReceivedTime & "#")
Set Duplicate = SearchFolder.Items.Find("[Subject] = '" & ESQ(Item.Subject) & "'")
If Duplicate Is Nothing Then
   HasDuplicate = False
Else
    HasDuplicate = True
End If

End Function

'this function escapes the single quotes in a string.
Private Function ESQ(str As String) As String

ESQ = Replace(str, "'", "''")

End Function
 

smiler44

Registered User.
Local time
Today, 07:38
Joined
Jul 15, 2008
Messages
641
sorry everyone I have not had email notification of your replies.
I would like to run the macro using excel
thank you for explaining the code I found runs from outlook, I thought it was from excel, doh

smiler44
 

smiler44

Registered User.
Local time
Today, 07:38
Joined
Jul 15, 2008
Messages
641
sneberg,
very kind of you. I will give it a go as soon as I can. Car break down is more pressing for me at the moment, stuffed without a car. I appreciate what you have done and will be back as soon as I can.

smiler44
 

sneuberg

AWF VIP
Local time
Yesterday, 23:38
Joined
Oct 17, 2014
Messages
3,506
sneberg,
very kind of you. I will give it a go as soon as I can. Car break down is more pressing for me at the moment, stuffed without a car. I appreciate what you have done and will be back as soon as I can.

smiler44

No rush. I'm still fighting with the code to detect duplicates and I haven't started on making sure the code can run from other Office applications. I hope to finish this up in a couple of days.

When you get a moment please explain why you want to run this from Excel rather than Outlook. It might help me ensure the code will do what you need it to do.
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:38
Joined
Sep 21, 2011
Messages
14,299
Sneuberg,
Could you possibly use the category you are setting and then check for the category when processing each email on subsequent runs??
 

sneuberg

AWF VIP
Local time
Yesterday, 23:38
Joined
Oct 17, 2014
Messages
3,506
Sneuberg,
Could you possibly use the category you are setting and then check for the category when processing each email on subsequent runs??

Thanks for the suggestion. I think that might work well but it would depend on the whether or not the categories were already being used for something.

I think I got this problem solved anyway. I was beating my head against the wall trying to make the item.find function work with dates. It turns out that's too imprecise. You have to format the dates as a string and then dates are no longer equal to themselves after the rounding that occurs. So now I'm just using the item.find for the email subject and if one is found I confirm it's a duplicate by comparing the last modified date and the receivedtime. Here's the code I have now.

Code:
Private Function HasDuplicate(ByRef SearchFolder As Outlook.MAPIFolder, ByRef Item As Outlook.MailItem) As Boolean

Dim Duplicate As Outlook.MailItem
Dim sFilter As String
If Item.Class <> olMail Then    'Duplication is not check for non mail items
    HasDuplicate = False
    Exit Function
End If

sFilter = "[Subject] = '" & ESQ(Item.Subject) & "'"
Set Duplicate = SearchFolder.Items.Find(sFilter)
HasDuplicate = False
If Not (Duplicate Is Nothing) Then
    If Duplicate.ReceivedTime = Item.ReceivedTime And Duplicate.LastModificationTime = Item.LastModificationTime Then
        HasDuplicate = True
    End If
End If

End Function

Actually I just found out this doesn't always work. So it needs some tweaking yet. Your suggestion is looking a lot better. I'd need to find out from the OP if this could be used.
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:38
Joined
Sep 21, 2011
Messages
14,299
Create your own category 'Email copied" :)

or CreationTime? or any other times?

? amail.CreationTime
12/08/2016 17:43:29
? format(amail.CreationTime,"yyyymmdd-hhmmss")
20160812-174329

I did not appear to get any rounding, or am I not understanding you correctly?

I think I would go with category as it is also a more visual indicator as well?
I can see which emails have had their attachments exported with mine.
 
Last edited:

sneuberg

AWF VIP
Local time
Yesterday, 23:38
Joined
Oct 17, 2014
Messages
3,506
Create your own category 'Email copied" :)

or CreationTime? or any other times?

? amail.CreationTime
12/08/2016 17:43:29
? format(amail.CreationTime,"yyyymmdd-hhmmss")
20160812-174329

I did not appear to get any rounding, or am I not understanding you correctly?

The rounding occurs when you do the formatting required by the Items Find Method. This Microsoft Web Page gives this example of how dates need to be handled


Code:
sFilter = "[LastModificationTime] > '" & Format("1/15/99 3:30pm", "ddddd h:nn AMPM") & "'"

Which works ok as this is using the greater than operator but something like

Code:
sFilter = "[LastModificationTime] = '" & Format( Item.LastModificationTime , "ddddd h:nn AMPM") & "'"

is never true. You would think you could do something like

Code:
sFilter = "[LastModificationTime] =#" & Item.LastModificationTime & "#"

as they are stored internally the same as in Access but that's not allowed. Last thing I was trying was using DateAdd to create a range but I couldn't seem to find what the range should be. It seems to be at least two minutes.

I wasn't aware that you can make your own categories. If I can do that then I think that's the way to go.
 
Last edited:

sneuberg

AWF VIP
Local time
Yesterday, 23:38
Joined
Oct 17, 2014
Messages
3,506
I just realized that it was stupid of me to keep fight with the Item Find method when I could just iterate through the folder like:

Code:
Private Function HasDuplicate(ByRef SearchFolder As Outlook.MAPIFolder, ByRef Item As Outlook.MailItem) As Boolean

Dim SearchItem As Outlook.MailItem

HasDuplicate = False
If Item.Class <> olMail Then    'Duplication is not check for non mail items
    Exit Function
End If

For Each SearchItem In SearchFolder.Items
    If SearchItem.Subject = Item.Subject _
        And SearchItem.ReceivedTime = Item.ReceivedTime _
        And SearchItem.LastModificationTime = Item.LastModificationTime Then
        HasDuplicate = True
        Exit For
    End If
Next SearchItem

End Function
 

sneuberg

AWF VIP
Local time
Yesterday, 23:38
Joined
Oct 17, 2014
Messages
3,506
The following code (also attached as CopyEmail.txt) copies emails from an Inbox folder in Personal Folders to the folders named paul, james, and john also in Personal Folder and then marks the items in the Inbox with the category "Email Copied". If the name space doesn't not have this category it is added.

This is how the folders look on my system where I test this.



In the code the way folders are designated are in general like:

NS.Folders("Main Folder").Folders("Sub Folderl")

You may have to adjust them to suite your environment.

The code is set up with late binding and so should work from any Microsoft application without references being added.

This version may not do what you want. If it doesn't let me know how you want this to work and I'll fix it. Now that I know a little more about this it might not take me as long.:rolleyes:

The main subroutine in this DistributeEmails.

The code:
Code:
#Const LateBinding = True
'this subroutine addes the category "Email Copied" to all item in the input Folder
#If LateBinding Then
    Private Sub MarkAsDistributed(ByRef Folder As Object)
    Dim Item As Object
#Else
    Private Sub MarkAsDistributed(ByRef Folder As Outlook.MAPIFolder)
    Dim Item As Outlook.MailItem
#End If

For Each Item In Folder.Items
    If Not Item.Categories = "Email Copied" Then
        Item.Categories = "Email Copied"
        Item.Save
    End If
Next Item

End Sub
'this function determines where a category with the name CategoryName exist in the name space NS
#If LateBinding Then
    Private Function CategoryExists(ByRef NS As Object, CategoryName As String) As Boolean
    Dim cat As Object
#Else
    Private Function CategoryExists(ByRef NS As Outlook.NameSpace, CategoryName As String) As Boolean
    Dim cat As Outlook.Category
#End If

CategoryExists = False
If NS.Categories.Count = 0 Then
    Exit Function
End If

' Enumerate the Categories collection.
For Each cat In NS.Categories
    If cat.Name = CategoryName Then
        CategoryExists = True
    End If
Next
Set cat = Nothing

End Function
'this subroutine copies all of the items in the SourceFolder to the DestinationFolder if the item in the SourceFolder
'do not have the category "Email Copied"
#If LateBinding Then
    Private Sub CopyAllItems(ByRef SourceFolder As Object, ByRef DestinationFolder As Object)
    Dim Item As Object
    Dim Copy As Object

#Else
    Private Sub CopyAllItems(ByRef SourceFolder As Outlook.MAPIFolder, ByRef DestinationFolder As Outlook.MAPIFolder)
    Dim Item As Outlook.MailItem
    Dim Copy As Outlook.MailItem
#End If

For Each Item In SourceFolder.Items
    If Not Item.Categories = "Email Copied" Then
        Set Copy = Item.Copy
        Copy.Move DestinationFolder
    End If
Next Item
Set Copy = Nothing

End Sub
'main program to copy email from the Inbox folder to other folders
Public Sub DistributeEmails()

#If LateBinding Then
    Dim OutLookApp As Object
    Dim NS As Object
    Dim SourceFolder As Object
    Dim DestFolder As Object
    Const olCategoryColorTeal = 6
#Else
    Dim OutLookApp As Outlook.Application
    Dim NS As Outlook.NameSpace
    Dim SourceFolder As Outlook.MAPIFolder
    Dim DestFolder As Outlook.MAPIFolder
#End If

Set OutLookApp = CreateObject("Outlook.Application")
Set NS = OutLookApp.GetNamespace("MAPI")

'this ensures the name space has the category "Email Copied"
If Not CategoryExists(NS, "Email Copied") Then
    'see https://msdn.microsoft.com/en-us/library/office/ff860420.aspx for possible colors
    NS.Categories.Add "Email Copied", olCategoryColorTeal
End If

'add source folder here
Set SourceFolder = NS.Folders("Personal Folders").Folders("Inbox")

'add destination folders here
Set DestFolder = NS.Folders("Personal Folders").Folders("paul")
CopyAllItems SourceFolder, DestFolder
Set DestFolder = NS.Folders("Personal Folders").Folders("james")
CopyAllItems SourceFolder, DestFolder
Set DestFolder = NS.Folders("Personal Folders").Folders("john")
CopyAllItems SourceFolder, DestFolder
MarkAsDistributed SourceFolder

MsgBox "Items have been copied"

Set NS = Nothing
Set SourceFolder = Nothing
Set DestFolder = Nothing

End Sub
 

Attachments

  • CopyEmail.txt
    3.3 KB · Views: 121
  • Folders.jpg
    Folders.jpg
    13.3 KB · Views: 274

Users who are viewing this thread

Top Bottom