Link to home
Start Free TrialLog in
Avatar of Tocogroup
TocogroupFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How do I create a subfolder in Outlook from an Excel VBA application ?

Hi All,

I have an Excel VBA application in which I open Outlook and create a folder. However, I would like to create a subfolder from the main folder but don't seem to be able to do so. Can anyone help ? My current code is below....

   Answer = MsgBox("Create a new Outlook folder ?", vbYesNoCancel)
   
   If Answer = vbYes Then
      OutlookFolderName = teOrderNo & " " & coClientName & " - " & coHeading
      
      Set ol = CreateObject("Outlook.Application")
      Set ns = ol.GetNamespace("MAPI")
      ParentFolder = "Personal Folders"
      MainFolder = "_Toco Orders"
      Set fl = ns.Folders.Item(ParentFolder).Folders.Item(MainFolder)
      fn = OutlookFolderName
   
      If Len(fn) > 0 Then
         Set mf = fl.Folders.Add(fn)
         Set mf = Nothing
         Set fl = Nothing
         Set ns = Nothing
         Set ol = Nothing
         MsgBox "A new Outlook folder has been created successfully", vbInformation
      End If
            
   End If

Open in new window


Many thanks
Toco
ASKER CERTIFIED SOLUTION
Avatar of Jacques Geday
Jacques Geday
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tocogroup

ASKER

Ah yes. That's great. Many thanks.