0

iw ant to create folder in outlook it contains set of accounts but i need to create folder in particualer email account using Excel VBA. kInldy help me on this.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Suhas14
  • 1
  • 1
  • Does this answer your question? [Get reference to additional Inbox](https://stackoverflow.com/questions/9076634/get-reference-to-additional-inbox) – niton Feb 12 '22 at 23:11

1 Answers1

0

It seems you need to automate Outlook from Excel VBA and create a folder in a profile. The Automating Outlook from a Visual Basic Application article describes all the required steps for that.

If you have got several accounts configured in the Outlook profile you can use the Stores object which represents a set of Store objects representing all the stores available in the current profile. For example:

Sub EnumerateFoldersInStores() 
 Dim colStores As Outlook.Stores
 Dim oStore As Outlook.Store 
 Dim oRoot As Outlook.Folder 
 
 On Error Resume Next 
 
 Set colStores = Application.Session.Stores
 
 For Each oStore In colStores 
   Set oRoot = oStore.GetRootFolder
   Debug.Print (oRoot.FolderPath)
   EnumerateFolders oRoot 
 Next
End Sub 
 
Private Sub EnumerateFolders(ByVal oFolder As Outlook.Folder) 
 Dim folders As Outlook.folders 
 Dim Folder As Outlook.Folder 
 Dim foldercount As Integer 
 
 On Error Resume Next 
 
 Set folders = oFolder.folders 
 foldercount = folders.Count 
 'Check if there are any folders below oFolder 
 If foldercount Then 
   For Each Folder In folders 
     Debug.Print (Folder.FolderPath) 
     EnumerateFolders Folder 
   Next 
 End If 
 
End Sub

A profile defines one or more email accounts, and each email account is associated with a server of a specific type. For an Exchange server, a store can be on the server, in an Exchange Public folder, or in a local Personal Folders File (.pst) or Offline Folder File (.ost). For a POP3, IMAP, or HTTP email server, a store is a .pst file.

You can use the Stores and Store objects to enumerate all folders and search folders on all stores in the current session. Since getting the root folder or search folders in a store requires the store to be open and opening a store imposes an overhead on performance, you can check the Store.IsOpen property before you decide to pursue the operation.

Once the Store object is found, you can use the GetDefaultFolder or GetRootFolder of the Store class to find the folder where a new folder should be created.

Finally, you may find the Storing Outlook Items page helpful.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • HI thank you for you replay, – Suhas14 Dec 18 '21 at 15:23
  • actually i m using below code but dont know how to add default folder for particular account, kindly help me regarding that. – Suhas14 Dec 18 '21 at 15:29
  • You can iterate over accounts in Outlook by using the `Namespace.Accounts` property. The [Account.DeliveryStore](https://learn.microsoft.com/en-us/office/vba/api/outlook.account.deliverystore) property returns a `Store` object that represents the default delivery store for the account. – Eugene Astafiev Dec 18 '21 at 17:04