Re: UserForm Always on Top
Quote:
Originally Posted by
mikepardon
In my Module file and place the rest of the code in the actual Userform, is this correct or incorrect?
Correct, however, the Private should be changed to Public when put in a module.
Re: UserForm Always on Top
Thanks for the quick reply Hack, I now no longer get the cannot find function message which that has fixed. Issue I now have is that when I run the application the form doesn't actually load though I get no errors
Code:
Call FormatUserForm(Me.Caption)
'CommandButton1.Visible = False
mlHwnd = FindWindow("Counter", "frmCounter") 'Change to match your userforms caption
Do While mlHwnd = 0
mlHwnd = FindWindow("Counter", "frmCounter") 'Change to match your userforms caption
DoEvents
Loop
' Set topmost
SetWindowPos mlHwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
CommandButton1.Caption = "Not Topmost"
'Minimize Excel's main window if you want to present the UserForm as a standard Form not "associated" with Excel.
Application.WindowState = xlMinimized
This is what I have in my UserForm_Initialize() which I'm sure is wrong! lol.
Re: UserForm Always on Top
Sorry for the double post, but can anyone help me with this?
Need to get this thing working but I'm honestly baffled!
Re: UserForm Always on Top
What is "Counter" and why the loop? Try this instead:
Code:
Private Sub UserForm_Initialize()
AlwaysOnTop (Me.caption)
End Sub
Private Sub AlwaysOnTop(caption As String)
Dim ret As Long
Dim hWnd As Long
hWnd = FindWindow(vbNullString, caption)
ret = SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
End Sub
Re: UserForm Always on Top
Quote:
Originally Posted by
His Nibbs
What is "Counter" and why the loop? Try this instead:
Code:
Private Sub UserForm_Initialize()
AlwaysOnTop (Me.caption)
End Sub
Private Sub AlwaysOnTop(caption As String)
Dim ret As Long
Dim hWnd As Long
hWnd = FindWindow(vbNullString, caption)
ret = SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
End Sub
Nibbs, thank you! You're a God :P.
Been trying to get this working for ages and it now works. Thanks mate :P.