Vijaykumarnachapalli
New Member
- Joined
- Apr 19, 2014
- Messages
- 3
I was referring to the code in the below link -
http://www.mrexcel.com/forum/excel-...erform-top-all-other-windows.html#post3783183
Above code that you've mentioned is not working! Please help me to get rid of the issue that i'm facing.
I have two user forms A and B; I load userform B when I click a button in userform A and wanted userform B to be on all of the other windows whichever is opened.
Problem: My user form B is not on top of other windows. Its goes behind other windows.
My module 'modFrameOnTop' has the below code:
My frame A (named: MainWindow) has a button 'StartButton' which has below code when clicked. My frame B is named as 'smackingFrame'
http://www.mrexcel.com/forum/excel-...erform-top-all-other-windows.html#post3783183
Above code that you've mentioned is not working! Please help me to get rid of the issue that i'm facing.
I have two user forms A and B; I load userform B when I click a button in userform A and wanted userform B to be on all of the other windows whichever is opened.
Problem: My user form B is not on top of other windows. Its goes behind other windows.
My module 'modFrameOnTop' has the below code:
Code:
Option Explicit
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const HWND_TOP = 0
Public Const HWND_BOTTOM = 1
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Declare PtrSafe Function SetWindowPos Lib "user32" _
(ByVal hWnd As LongPtr, _
ByVal hWndInsertAfter As LongPtr, _
ByVal X As LongPtr, _
ByVal Y As LongPtr, _
ByVal cx As LongPtr, _
ByVal cy As LongPtr, _
ByVal uFlags As LongPtr) As Long
Public Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
My frame A (named: MainWindow) has a button 'StartButton' which has below code when clicked. My frame B is named as 'smackingFrame'
Code:
Private Sub StartButton_Click()
MainWindow.Hide
smackingFrame.Show
Const C_VBA6_USERFORM_CLASSNAME = "smackingFrame"
Dim ret As Long
Dim formHWnd As Long
'Get window handle of the userform
formHWnd = FindWindow(C_VBA6_USERFORM_CLASSNAME, smackingFrame.Caption)
If formHWnd = 0 Then
Debug.Print Err.LastDllError
End If
'Set userform window to 'always on top'
ret = SetWindowPos(formHWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
If ret = 0 Then
Debug.Print Err.LastDllError
End If
Application.WindowState = xlMinimized
End sub
Last edited by a moderator: