How to bring Calendar window to top after open?

D

deko

I have an Access 2003 app running on Vista that opens the Outlook Calendar
like this:

Set olapp = New Outlook.Application
Set olns = olapp.GetNamespace("MAPI")
olns.GetDefaultFolder(olFolderCalendar).display
'hide the navigation pane
Set olxp = olapp.ActiveExplorer
olxp.ShowPane olNavigationPane, False

The problem is the calendar window opens behind the Access application
window.

Is there any way to ensure the Outlook Calendar opens on top?

I've tried a few things but none seem to work. For example:

olapp.ActiveWindow 'no help

Using the Windows API like this:

Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" (ByVal lpclassname As String, _
ByVal lpWindowName As String) As Long
Private Declare Sub BringWindowToTop _
Lib "user32" (ByVal HWND&)

Public Function ShowOutlook()
Dim HWND As Long
HWND = FindWindow(vbNullString, "Calendar - Microsoft Outlook")
BringWindowToTop HWND

is there a easier way?

Thanks in advance.
 
K

Ken Slovak - [MVP - Outlook]

There aren't any easy ways to manipulate the z-order of the Outlook Explorer
window. I usually found that depending on the exact circumstances that were
in effect when the window is opened that using SetForegroundWindow or
SetWindowLong or SetWindowPos with the HWND_TOP or HWND_TOPMOST arguments
work the best.

HWND_TOPMOST will keep the window on top even if you click to activate
another window so that's the least desirable way to do it.

The window class name you want for the Explorer window for FindWindow would
be "rctrl_renwnd32".
 
K

Ken Slovak - [MVP - Outlook]

Sometimes. I've seen that fail to work as expected sometimes, and the window
remains on top of the z-order no matter what you do. I've tried to stay away
from HWND_TOPMOST since I discovered that. I've settled on using
SetWindowLong() most of the time now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top