Results 1 to 2 of 2
2007-10-30, 10:35 #1
- Join Date
- Oct 2007
- Thanked 2 Times in 1 Post
Forms, minimizing / maximising (2003)
If I have a document based on a template, which contains an add-in which opens a Userform for the user when a new document is created.. is there a way to minimise the Word Application window and have the Form displayed *on top* of other windows that the user may have open?
At the moment I have:
Application.WindowState = wdWindowStateMinimize
Application.WindowState = wdWindowStateNormal
Which almost works fine, except the 'Doc Properties' Userform is then hidden behind any other application window that the user may have open. Is there any way to force it to the front?
I don't absolutely have to hide the Word application window, but it looks a bit cleaner and is a bit faster (even if screen updating is switched off).
2007-10-30, 10:45 #2
- Join Date
- Mar 2002
- Thanked 29 Times in 29 Posts
Re: Forms, minimizing / maximising (2003)
You can use this code behind your userform:
Const HWND_TOPMOST = -1
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40
Public hWnd As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Sub 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)
Private Sub UserForm_Activate()
SetWindowPos hWnd, HWND_TOPMOST, 0, 0, 0, 0, _
SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
Private Sub UserForm_Initialize()
hWnd = FindWindow("ThunderDFrame", Me.Caption)
The part up to and including SetWindowPos must be at the top of the module, before all other Subs and Functions.
Source: How to show a Userform on top of other applications.