Results 1 to 4 of 4

Thread: Create OutlookFolder

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    402

    Create OutlookFolder

    Ok, this may not be strictly VB.net however I am hoping someone can help

    In VBA - outlook I am trying to create a folder directly under the high level account name (not the in box or Drafts etc. but at the same level)

    the code I have is :-

    Code:
    Dim oloUtlook As Outlook.Application
    Dim ns As Outlook.NameSpace
    Dim itm As Object
    
    'On Error Resume Next
    
    'Application.ScreenUpdating = False
    
    Set oloUtlook = CreateObject("Outlook.Application")
    Set ns = oloUtlook.GetNamespace("MAPI")
    Set itm = ns.GetDefaultFolder(olFolderInbox)
    
    itm.Folders.Add ("aaaa")
    
    Set oloUtlook = Nothing
    Set ns = Nothing
    Set itm = Nothing
    
    MsgBox "Outlook Set Up Succesfully"
    ThisWorkbook.Close
    
    End Sub
    The problem is how do I get it to create the folder at the same level as in box etc, not underneath it as there has to be a GetDefaultFolder and the only allowable values are inbox, drafts etc.
    Last edited by Signalman; Dec 23rd, 2020 at 06:15 PM.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: Create OutlookFolder

    Our 'Office Development/VBA' forum is more appropriate for this question, so I've moved the thread there.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    402

    Re: Create OutlookFolder

    Ok i think i have got it to work, by chance. - for reference for others.

    replacing the
    Code:
    Set itm = ns.GetDefaultFolder(olFolderInbox)
    with
    Code:
    Set itm = ns.folders("mailbox name")

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Create OutlookFolder

    there are a couple of options, by default the parent name is personal folders, but the safest in case the of any other name, would be

    Code:
    Set itm = ns.GetDefaultFolder(olFolderInbox).parent
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width