teachnmyself
Board Regular
- Joined
- Jan 29, 2008
- Messages
- 110
hey guys..I aquired this code from one of you and i cant seem to get it to work. The purpose of it is to allow the userform to stay up on the screen even if excel is minimized(or closed would be better) If anybody has any idea how to make this work please help me... the name of my form is Userform1..if it helps write it.
Code:
Option ExplicitPrivate Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, _ByVal lpWindowName As String) As Long Private 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 Const HWND_TOPMOST = -1Const HWND_NOTOPMOST = -2Const SWP_NOSIZE = &H1Const SWP_NOMOVE = &H2Const SWP_NOACTIVATE = &H10Const SWP_SHOWWINDOW = &H40 Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As LongPrivate Sub UserForm_Initialize() Dim hWnd As Long Application.WindowState = xlMinimized While hWnd = 0 DoEvents hWnd = FindWindow(vbNullString, Me.Caption) Wend SetWindowPos hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE SetForegroundWindow FindWindow("xlmain", Application.Caption)End SubPrivate Sub UserForm_Terminate() Application.WindowState = xlNormalEnd Sub
</PRE>Credit goes to whoever wrote the code - found it online but have since lost the link :rolleyes:
<!-- / message --><!-- sig -->