Showing Userform Problem
You can control which window appears "on top" using Windows API functions;
here is the code:
Declare Function FindWindow% Lib "user32" Alias "FindWindowA" _
(ByVal lpclassname As Any, _
ByVal lpCaption As Any)
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
' Constant for hWndInsertAfter
Global Const HWND_TOPMOST = -1 ' Puts the Window permanently on top of all
others
' Constants for wFlags:
Global Const SWP_NOSIZE = &H1 ' Do not resize the Window
Global Const SWP_NOMOVE = &H2 ' Do not move the Window
Sub TopMost(WindowTitle as String)
Dim hwnd%
hwnd% = FindWindow%(0&, WindowTitle)
Call SetWindowPos(hwnd%, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or
SWP_NOSIZE)
End Sub
WindowTitle needs to be the exact .Caption of the window you want to move to
the top, so the best way to implement the code is as follows:
UserForm1.Show
TopMost(UserForm1.Caption)
--
- K Dales
"Henry Stockbridge" wrote:
Hi,
I have created an Excel template used as a small application. Users
start the application by first hyperlinking to the directory where the
..xlt resides, and then by opening the .xlt file.
The problem arises when the Users open the .xlt. The Userform shows,
but underneath the directory window. The Users then have to minimize
the directory window to access the Userform. How annoying. Is there a
way to have the Userform load and show on top?
Any help you can lend would be appreciated.
Here is my start up code:
'------------------------------------------
Private Sub Workbook_Open()
Application.Visible = False
frmWelcome.Show
End Sub
'------------------------------------------
Henry
|