Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 793
Default Keep Workbook Window On Top

I have a workbook which I open (in a new instance of Excel) at the
right-bootom of the screen... I want to keep it on top of all other windows
as long as it is not closed by me.

I need help to accomplish this. I have tried the SETWINDOWSPOS but could

I want to work it in both Excel 2007 and 2003.Also can you recommend any
add-ins and/or tools (freeware or otherwise) which are free of
spyware/malware?

Thanks in advance,
Sheeloo
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default Keep Workbook Window On Top

Try code like the following. You can play around with the values of
XLWidth and XLHeight to get the position as you desire.



Public 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
Public Declare Function GetSystemMetrics Lib "user32.dll" ( _
ByVal nIndex As Long) As Long
Public Declare Function MoveWindow Lib "user32" ( _
ByVal HWnd As Long, ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal bRepaint As Long) As Long

Public Const HWND_TOPMOST = -1
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOACTIVATE = &H10
Public Const HORZRES = 8
Public Const VERTRES = 10
Public Const SM_CXSCREEN = 0
Public Const SM_CYSCREEN = 1

Dim XLApp As Excel.Application

Sub AAA()

Dim HWnd As Long
Dim ScreenX As Long
Dim ScreenY As Long
Dim XLLeft As Long
Dim XLWidth As Long
Dim XLTop As Long
Dim XLHeight As Long

Set XLApp = New Excel.Application
XLApp.Visible = True

ScreenX = GetSystemMetrics(SM_CXSCREEN)
ScreenY = GetSystemMetrics(SM_CYSCREEN)

XLWidth = 200
XLLeft = ScreenX - XLWidth
XLHeight = 150
XLTop = ScreenY - XLHeight
HWnd = XLApp.HWnd
XLApp.WindowState = xlNormal
SetWindowPos HWnd, HWND_TOPMOST, XLLeft, XLTop, _
XLWidth, XLHeight, SWP_NOMOVE + SWP_NOACTIVATE
MoveWindow HWnd, XLLeft, XLTop, XLWidth, XLHeight, True
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Sun, 7 Jun 2009 10:11:01 -0700, Sheeloo
wrote:

I have a workbook which I open (in a new instance of Excel) at the
right-bootom of the screen... I want to keep it on top of all other windows
as long as it is not closed by me.

I need help to accomplish this. I have tried the SETWINDOWSPOS but could

I want to work it in both Excel 2007 and 2003.Also can you recommend any
add-ins and/or tools (freeware or otherwise) which are free of
spyware/malware?

Thanks in advance,
Sheeloo

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 793
Default Keep Workbook Window On Top

Hello Chip,

Thanks a lot. It works exactly as I wanted.

I will compare with what I had tried to find out what I was doing wrong...

Just wanted to tell you that I have learnt a lot from your articles on your
website... Thanks again for sharing your wisdom.

Regards,
Sheeloo
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I capture the workbook window? Stacy Excel Discussion (Misc queries) 1 December 2nd 08 08:12 AM
How do I open a workbook using a different window Dean Menzies Excel Discussion (Misc queries) 1 August 31st 08 01:42 PM
Workbook window tiling Barry McConnell Excel Discussion (Misc queries) 0 July 6th 07 02:06 PM
Opening a workbook window maximized John Crosher Excel Discussion (Misc queries) 7 February 17th 07 07:34 PM
The window opens in a smaller window not full sized window. Rachael Excel Discussion (Misc queries) 0 November 7th 06 09:04 PM


All times are GMT +1. The time now is 07:05 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"