1

I am trying to move some emails that comes into our shared inbox (ABC COMPANY) to a subfolder (A&D) that is created inside a main folder (DAILY INFO). I have only found in the web, a macro that moves the emails from the shared inbox to the main folder, but not into the sub folder. Here is the code i found.

 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("ABC COMPANY").Folders("Inbox")
    Set sharedDestinationFolder = sharedInbox.Folders("DAILY INFO")

    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
2
  • Please don't use CAPS for the headline. Commented Nov 4, 2019 at 8:32
  • okay. Will remember not to do so. Commented Nov 4, 2019 at 11:03

1 Answer 1

1

Every folder contains a folders-collection that holds its subfolders.

Assuming that your folders exists, do something like

Set sharedDestinationFolder = sharedInbox.Folders("DAILY INFO")
Set sharedDestinationFolder = sharedDestinationFolder.Folders("A&D")

of course you could do this with a single statement, but this makes it harder to debug if something fails

Set sharedDestinationFolder = sharedInbox.Folders("DAILY INFO").Folders("A&D")
Sign up to request clarification or add additional context in comments.

2 Comments

Hi Thomas, Thank you so much. It worked!!! Really appreciate it :)
Hi @yuki, as you haven't done the StackOverflow tour (you should do so to understand how SO works): You can (and should) flag an answer as "accepted" if it answered your question best. If a question get's several answers, the "accepted" one is sorted to the top. And in the question list the question is marked in green to show that it has already an accepted answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.