When opening a desired folder in Outlook with explorer.CurrentFolder = folder_object_to_open) it opens, but does not jump there. I still need to scroll manually.

Victor Q 0 Reputation points
2025-05-20T16:17:16.41+00:00

Dear MS learn Team,

When opening a desired folder in Outlook with python

" outlook_app = win32com.client.Dispatch("Outlook.Application")

explorer = outlook_app.ActiveExplorer()

explorer.CurrentFolder = folder_object_to_open"

the navigation pane does select the folder and mark it bold,

but it DOES NOT jump there. I still need to scroll manually.

When I used to do this with VBA it did refocus, but now with python I don't know how to do it.

Please let me know how to get Outlook to center navigation pane on the selected and opened folder.

Kind Regards,

Vic Q

Outlook | Windows | Classic Outlook for Windows | For business
{count} votes

1 answer

Sort by: Most helpful
  1. Victor Q 0 Reputation points
    2025-05-21T07:28:30.1766667+00:00

    First of all, thanks for engaging on this conversation!

    Exactly in VBA I had a Macro which was able to look for a folder I search by words and then open it with:

    Set objFolder = GetFolder(MyfTxt)

    Set objOlApp.ActiveExplorer.CurrentFolder = objFolder

    Yes, it worked, open the folder and navigation panel re-focused as desired.

    But my company has remove Macros from outlook and I had to become creative using python instead:

    if temp_folder_obj:
      outlook_app = win32com.client.Dispatch("Outlook.Application") # Get app object
      explorer = outlook_app.ActiveExplorer()
    
      # Check if the stored folder object is still valid
      try:
          _ = temp_folder_obj.Name # Access a property to check validity
          folder_object_to_open = temp_folder_obj # It's valid, use it
      except pythoncom.com_error:
           # Object likely invalid, try resolving by path again
            .......
    
      # Navigate in Outlook if we have a valid object
      if folder_object_to_open:
            explorer.CurrentFolder = folder_object_to_open
            window['-STATUS-'].update(f'Opened: {selected_path}')
            sg.popup_quick_message(f'Navigated to: {selected_path}', auto_close_duration=3) #, location=window.current_location())
      else:
            # This means re-resolving also failed
            raise Exception("Could not re-validate or resolve folder object.")
    

    in python explorer.CurrectFolder = folder_object_to_open

    does open the folder and I can see all the emails in the Folder, but the navigation pane does not re-focus, forcing me to scroll down the many folders until I recognized the open folder in "bold"

    Looking forward for your feedback.

    Regards,

    Vic


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.