Log in

View Full Version : [SOLVED:] VBA Outlook-Move mail shared Folder to shared subfolder



daliman
01-31-2017, 01:13 AM
Hi,

I've been roaming the internet for a day now and have not been able to find my solution.
I like to move selected mail to a subfolder in a shared folder. (Both mail are in the same shared email box.)

What I found so far is the ability to get the sharedfolder with the code below.
I have not been able to implement this into a working piece of code.
(But my VBA knowledge is very limited, so that's probably the second problem...)

Does anyone have found a solution or can help me solve this problem?



'slipstick.com/developer/working-vba-nondefault-outlook-folders/
Dim NS As Outlook.NameSpace Dim objOwner As Outlook.Recipient

Set NS = Application.GetNamespace("MAPI")
Set objOwner = NS.CreateRecipient("Commerciele_Ondersteuning")
objOwner.Resolve

skatonni
01-31-2017, 01:25 PM
If you already have the shared mailbox open to select mail then I do not think you need to Resolve.

This code moves selected mail to the shared subfolder named "Test" directly under the Inbox. Moving as shown in this example is much slower than native Outlook.



Option Explicit

Private Sub MoveSelectionToFolder()
Dim NS As NameSpace

Dim sharedInbox As Folder
Dim sharedDestinationFolder As Folder

Dim sharedItems As Selection

Dim i As Long

Set NS = Application.GetNamespace("MAPI")
Set sharedInbox = NS.Folders("Commerciele_Ondersteuning").Folders("Inbox")
Set sharedDestinationFolder = sharedInbox.Folders("Test")

Set sharedItems = ActiveExplorer.Selection

' Counting in reverse
' when changing the number of items in a collection
For i = sharedItems.count To 1 Step -1
sharedItems(i).Move sharedDestinationFolder
Next i

ExitRoutine:
Set NS = Nothing
Set sharedItems = Nothing
Set sharedInbox = Nothing
Set sharedDestinationFolder = Nothing

End Sub

daliman
01-31-2017, 11:38 PM
If you already have the shared mailbox open to select mail then I do not think you need to Resolve.

This code moves selected mail to the shared subfolder named "Test" directly under the Inbox. Moving as shown in this example is much slower than native Outlook.




Thank you skatonni, This is exactly what I was trying to do.
This is working like a charm.


Thanks very very much!