Outlook and Word Addin - Bring New Mail Window to Focus

Add-in Express™ Support Service
That's what is more important than anything else

Outlook and Word Addin - Bring New Mail Window to Focus
Outlook And Word 2016 
devin@lilliangroup.com-1




Posts: 19
Joined: 2015-11-20
Windows 10. In Word 2016 I have created an addin with a macro to handle attaching the current word document to a new email in Outlook 2016. It does so by calling a public sub in my Outlook 2016 addin. There are specific reasons why I do not just initiate the new email directly from the Word addin, because there are variables in the Outlook addin that need to be utilized.

The Word macro successfully executes and Outlook creates a new mail item with the correct file attached. But, the new mail item does not come to the forefront and display, even though in the Outlook sub I have tried calling comMailItem.Activate, and I have even handled the Inspector item for the mail item and also called comInspector.Activate. How can I simply force the focus to the new mail item so that it appears on the screen instead of staying hidden behind the Word document?
Posted 05 Nov, 2018 12:11:18 Top
Andrei Smolin


Add-in Express team


Posts: 17123
Joined: 2006-05-11
Hello,

In the Outlook add-in, you can create a delay using the approach we describe in section Wait a Little, see the PDF file in the folder {Add-in Express}\Docs on your development PC. When the OnSendMessage event occurs, call Inspector.Activate.

Alternatively, call the SetForegroundWindow API function (see https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setforegroundwindow). You get the handle (HWND) to pass to that function by casting Outlook.Inspector to IOlweWindow (see https://docs.microsoft.com/en-us/windows/desktop/api/oleidl/nn-oleidl-iolewindow) and calling IOleWindow.GetWindow. This approach may require creating a delay, too.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 07 Nov, 2018 07:45:33 Top