How to make Excel the Top-Most application programmatically?

  • Thread starter Thread starter R Avery
  • Start date Start date
R

R Avery

I have Excel checking a file every so often for a particular command,
and whenever it finds a certain command, I want it to bring Excel to the
front and prompt the user.

Similarly, I would like to be able to send Excel to the back whenever
some other command was inside a file.

How could I achieve this? Any help would be appreciated.
 
I don't think you can do this. The closest you can come is to use

AppActivate Application.Caption

This will cause the Excel icon in the Taskbar to blink, but won't
actually make the application active.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
R Avery said:
I have Excel checking a file every so often for a particular command,
and whenever it finds a certain command, I want it to bring Excel to the
front and prompt the user.

Similarly, I would like to be able to send Excel to the back whenever
some other command was inside a file.

How could I achieve this? Any help would be appreciated.

It can be done using the win32 API

In a code module declare the function

Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal
hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long,
ByVal cy As Long, ByVal Wflags As Long) As Long

then get the Excel Windows handle

Dim Winhandle as Long
Winhandle=Application.Hwnd

Then call the following sub

FloatWindow(Winhandle)


Public Sub Floatwindow(Winhandle As Long)
' -------------------------------------
' This routine makes the window who's
' handle is passed always on top
' -------------------------------------

Dim Wflags As Integer
Wflags = 2 Or 1
Call SetWindowPos(Winhandle, -1, 0, 0, 0, 0, Wflags)

End Sub

Keith
 

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

Back
Top