Consulting

Results 1 to 5 of 5

Thread: Outlook Folder Path

  1. #1
    VBAX Newbie
    Joined
    Apr 2019
    Posts
    3
    Location

    Outlook Folder Path

    Goo day all

    I have this problem pointing the correct outlook subfolder path, it gives me "run time error 13".

    The sub folder is "CHHIEW\Hong\Report", it's outside of inbox folder, have tried many times changing the "/" and "" but still did'nt work, anyone got any idea how to fix this?

    Thank you for your help
    Private Sub Application_Startup()
    
    
    Dim olNs As Outlook.NameSpace
    Dim Inbox  As Outlook.MAPIFolder
    Dim olFolder As Outlook.MAPIFolder
    Dim GetFolder As Outlook.MAPIFolder
    Dim objFolder As Outlook.MAPIFolder
    
    
        Set olNs = Application.GetNamespace("MAPI")
     Set Inbox = olNs.GetDefaultFolder("\\CHHIEW\Hong\Report")
      
       Set Items = Inbox.Items
        
    End Sub
    Last edited by tg23; 04-19-2019 at 06:14 PM.

  2. #2
    I don't think it is possible to set the inbox in this way, however to get the folder, you would need code like the following. The message boxes are purely for testing.

    Sub Test()
    Dim olNS As NameSpace
    Dim olStore As Store
    Dim olItem
    Dim olFolder As Folder
    Dim bFound As Boolean
        Set olNS = Application.GetNamespace("MAPI")
        For Each olStore In olNS.Stores
            If olStore.DisplayName = "CHHIEW" Then
                bFound = True
                Exit For
            End If
        Next olStore
        If Not bFound Then
            MsgBox "The store CHHIEW was not found"
            GoTo lbl_Exit
        End If
        Set olFolder = olStore.GetRootFolder.folders("Hong").folders("Report")
        MsgBox olFolder.FolderPath
    lbl_Exit:
        Exit Sub
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Newbie
    Joined
    Apr 2019
    Posts
    3
    Location
    Hi Gmayor,
    Thanks for your help. yes i can see the msgbox displayed the folder path, but how can i incorporate that path in my script?

    sorry i am newbie with limited programming knowledge to outlook vba.

    Thanks

  4. #4
    The message box is there to show that the code works. olFolder is the folder related to that path.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    VBAX Newbie
    Joined
    Apr 2019
    Posts
    3
    Location
    Gmayor,
    Thank you so much. will explore and figure out this.

    Thanks

Posting Permissions

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