user3260213
user3260213

Reputation: 1

Using VBA how do I move emails in outlook 2010 from my secondary account inbox into specified folder

I have two e-mail addresses connected to outlook 2010. I am using a VBA macro to move the selected messages from inbox to specified folders. It works perfectly for my primary account. Unfortunately I was unable to use it for my secondary account. It always moves messages to my primary account folders. My question is this: how do I set up a valid reference to my secondary account, to fix the problem? should I provide my full email address in place of "myemail"?

Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Set objNS = GetNamespace("MAPI")
Set objFolder = objNS.Folders("myemail")
Set objFolder = objFolder.Folders("XYZ")

Upvotes: 0

Views: 769

Answers (1)

mnkypete
mnkypete

Reputation: 329

The best and most transparent way to do this would probably to open the Outlook Store for the secondary account first. You can get a list of all stores (Data-File in Outlook) with the following command (see Link)

Set objStores = objNS.Stores

You can then call GetRootFolder or GetSpecialFolder on the store object to retrieve the sub-folder references. Also check http://msdn.microsoft.com/en-us/library/office/bb206775(v=office.12).aspx for an example on how to get informations about the store.

Upvotes: 0

Related Questions