none
No mail items visible when auto expanding public folders RRS feed

  • Question

  • Hi,

    I've a problem with the following code:

    Private objNS As Outlook._NameSpace Private IsExchangeUser As Boolean = False Private StdFolder As Outlook.MAPIFolder

    Private Sub Application_Startup() Handles Application.Startup 'Set Session: objNS = Application.Session 'Set standard folder: StdFolder = Application.ActiveExplorer.CurrentFolder 'Check if user is an exchange user, otherwise exit processing: Dim addrEntry As Outlook.AddressEntry = objNS.CurrentUser.AddressEntry If Not addrEntry.Type = "EX" Then MsgBox("Message", MsgBoxStyle.Exclamation, "Caption") Exit Sub Else IsExchangeUser = True End If 'Execute Expansion: ExpandFolders() End Sub Private Sub ExpandFolders() Try Dim objFolder As Outlook.MAPIFolder = objNS.Folders.Item("Public Folders - " & objNS.CurrentUser.AddressEntry.GetExchangeUser.PrimarySmtpAddress) LoopFolders(objFolder.Folders, True) 'Set ActiveFolder Inbox: Application.ActiveExplorer.CurrentFolder = StdFolder Catch ex As Exception MsgBox("Message" & vbNewLine & vbNewLine & ex.Message.ToString, MsgBoxStyle.Critical, "Error") End Try End Sub Private Sub LoopFolders(Folders As Object, ByVal bRecursive As Boolean) For Each F As Outlook.MAPIFolder In Folders Application.ActiveExplorer.CurrentFolder = F If bRecursive Then If F.Folders.Count Then LoopFolders(F.Folders, bRecursive) End If End If Next End Sub

     

    After opening Outlook 2013 all public folders and subfolders will get expanded automatically and the users inbox (StdFolder) is selected. The problem is that no item is visible in the right container. That means when I click on Inbox or Calendar or where else nothing is visible in the right container. It is just a empty white window.

    Has anyone an idea how to fix my problem?

    Many thanks in advance.


    Regards.


    Tuesday, December 2, 2014 10:11 PM

Answers

  • All I would say is that you're trying to doing something that Outlook doesn't natively support - you'll notice that Public Folders cannot be chosen as a startup folder in the Advanced Options page.  You may continue to experience strange behavior if you try to immediately navigate to a Public Folder during startup.

    One last thing to try is to wait until Explorer.Activate fires for the first time, or perhaps don't switch folders until a timer has elapsed (say 5 seconds) to give time for Outlook to fully initialize.


    Eric Legault (MVP: Outlook)
    Co-author, Microsoft Office 2013 Professional Step-By-Step
    Try some Outlook Appins!

    Wednesday, December 3, 2014 3:08 PM
    Moderator

All replies

  • I think you broke Outlook LOL!  Seriously though, setting the active folder repeatedly for a large number of folders during Outlook startup is not a good idea, and will probably lead to the strange behavior that you are currently seeing.  I'd suggest just setting the active folder once for the last folder in the loop and then try setting the Inbox as the active folder - it may work without the side-effects you are seeing.


    Eric Legault (MVP: Outlook)
    Co-author, Microsoft Office 2013 Professional Step-By-Step
    Try some Outlook Appins!

    Tuesday, December 2, 2014 10:45 PM
    Moderator
  • Hi,

    thanks for the response.

    When I try the following code I have the same issue:

    Private Sub Application_Startup() Handles Application.Startup
            'Set Session:
            objNS = Application.Session
    
            'Set standard folder:
            StdFolder = Application.ActiveExplorer.CurrentFolder
    
            'Check if user is an exchange user, otherwise exit processing:
            Dim addrEntry As Outlook.AddressEntry = objNS.CurrentUser.AddressEntry
    
            If Not addrEntry.Type = "EX" Then
                MsgBox("Message", MsgBoxStyle.Exclamation, "Caption")
                Exit Sub
            Else
                IsExchangeUser = True
            End If
    
            'Load the last public folder expansion status:
            'LoadSettings()
    
            'Execute Expansion:
            ExpandFolders()
        End Sub
    
    Private Sub ExpandFolders()
            Try
                Dim objFolder As Outlook.MAPIFolder = objNS.Folders.Item("Public Folders - " & objNS.CurrentUser.AddressEntry.GetExchangeUser.PrimarySmtpAddress)
                Application.ActiveExplorer.CurrentFolder = objFolder
    
                'objFolder = objFolder.Folders.Item(1)
    
                'LoopFolders(objFolder.Folders, True)
    
                'Set ActiveFolder Inbox:
                'Application.ActiveExplorer.CurrentFolder = StdFolder
    
            Catch ex As Exception
                MsgBox("Message" & vbNewLine & vbNewLine & ex.Message.ToString, MsgBoxStyle.Critical, "Error")
            End Try
        End Sub

    So I do the "Application.ActiveExplorer.CurrentFolder" just one time and I'm running into the same problem.

    The "Public Folders - xxx" is expanded!

    Maybe any other suggestions?

    Many thanks in advance.


    Regards.


    Wednesday, December 3, 2014 12:34 AM
  • Hi DeveloperGermany,

    Based on the description, when you set the active folder for the Outlook exploer, there is a blank window at the right area of explore where sholud display the items and reading pane.

    I am failed to reproduce the issue using code below:

    Sub ChangeFolder()
    
    If Application.ActiveExplorer.CurrentFolder = Application.Session.GetDefaultFolder(olFolderDrafts) Then
        Set Application.ActiveExplorer.CurrentFolder = Application.Session.GetDefaultFolder(olFolderInbox)
    Else
        Set Application.ActiveExplorer.CurrentFolder = Application.Session.GetDefaultFolder(olFolderDrafts)
    End If
    
    End Sub

    Which version of Outlook are you using? Could this issue be reproduced when you click the folder manually? 

    I suggest that you repair or update the Office to the latest version to see whether the issue was fixed.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, December 3, 2014 5:45 AM
    Moderator
  • All I would say is that you're trying to doing something that Outlook doesn't natively support - you'll notice that Public Folders cannot be chosen as a startup folder in the Advanced Options page.  You may continue to experience strange behavior if you try to immediately navigate to a Public Folder during startup.

    One last thing to try is to wait until Explorer.Activate fires for the first time, or perhaps don't switch folders until a timer has elapsed (say 5 seconds) to give time for Outlook to fully initialize.


    Eric Legault (MVP: Outlook)
    Co-author, Microsoft Office 2013 Professional Step-By-Step
    Try some Outlook Appins!

    Wednesday, December 3, 2014 3:08 PM
    Moderator