1

I've developed a VSTO add-in for Outlook using c#. In this add-in, I want to programatically select a public folder and navigate the user to it. The line I am using is:

_application.ActiveExplorer().CurrentFolder = projectFolder;

This successfully displays the contents of the folder and highlights the folder in the 'Folder List' tree, but it doesn't automatically scroll the folder list down so that the selected folder is visible on screen.

In a previous project, I used the same line of code (but in a VB6 COM add-in).

Set objOutlook.ActiveExplorer.CurrentFolder = mapDestFolder

In this case, it does scroll the folder view as desired.

Both add-ins above a are running in Outlook 2007

Is there any way I can get it to scroll the folder view when selecting the desired folder using the VSTO add-in?

tassieboy
  • 160
  • 1
  • 1
  • 11

2 Answers2

1

You have add one row before setting up CurrentFolder, as follows:

objOutlook.ActiveExplorer.Activate # This is what you need to add to your code.
Set objOutlook.ActiveExplorer.CurrentFolder = mapDestFolder

The ActiveExplorer.Activate will do the trick of moving the focus to ActiveExplorer. And when you setup CurrentFolder in the other row, it will already automatically scroll to your specified folder.

zarak
  • 2,933
  • 3
  • 23
  • 29
  • This seems to work (in both Outlook 2007 and 2016) when the UI triggering the folder selection is in a separate dialog than outlook. However, when the UI triggering the folder selection is part of an outlook (2016) ribbon, the folder view still does not scroll. Used to work fine when the same addin was running in outlook 2007. – Jimmy Aug 21 '17 at 15:44
  • Still doesn't work in Outlook 2021 :( – Jimmy Sep 21 '22 at 15:27
  • In fact, in Outlook 2021, it seems that Outlook will only scroll to the right folder if Outlook is in the foreground (so, if another app sets the active folder, then Outlook won't scroll to that folder). I haven't found a good way to bring Outlook to the foreground before setting the active folder; https://stackoverflow.com/a/27172404/68936 doesn't seem to work. – Jimmy Sep 21 '22 at 15:50
0

I had the same problem too, and got it working by doing nothing special other than setting the CurrentFolder property. I seem to remember the problem was to do with when the CurrentFolder is set.

In my code the Explorer.CurrentFolder is set last. So try setting the Explorer.CurrentFolder last.

m_collard
  • 2,008
  • 4
  • 29
  • 51