I am totaly new to VBA world and right now I'm completely lost in those below code where i want to combine them both and make able to run on single userform.
Option Explicit
'API function to enable/disable the Excel Window
Private Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function EnableWindow Lib "user32" _
(ByVal hWnd As Long, ByVal bEnable As Long) 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
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const FLAGS As Long = SWP_NOMOVE Or SWP_NOSIZE
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private mlHWnd As Long
Private mbDragDrop As Boolean
Private FormHWnd As Long
Private Sub cmdNotTop_Click()
SetWindowPos FormHWnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS
End Sub
Private Sub cmdTop_Click()
SetWindowPos FormHWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS
End Sub
Private Sub UserForm_Activate()
On Error Resume Next
'Find the Excel main window
mlHWnd = FindWindowA("XLMAIN", Application.Caption)
FormHWnd = FindWindowA(vbNullString, Me.Caption)
Call cmdTop_Click
'Enable the Window - makes the userform modeless
EnableWindow mlHWnd, 1
mbDragDrop = Application.CellDragAndDrop
Application.CellDragAndDrop = False
End Sub
Private Sub btnOK_Click()
Application.CellDragAndDrop = mbDragDrop
Call cmdNotTop_Click
Unload Me
End Sub
and
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLongA Lib "user32" _
(ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLongA Lib "user32" _
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
'
Private Sub UserForm_Activate()
Dim hWnd As Long, exLong As Long
If Application.Version < 9 Then
hWnd = FindWindow("ThunderXFrame", Me.Caption)
Else
hWnd = FindWindow("ThunderDFrame", Me.Caption)
End If
exLong = GetWindowLongA(hWnd, -16)
If (exLong And &H30000) = 0 Then
SetWindowLongA hWnd, -16, exLong Or &H20000
Me.Hide: Me.Show
End If
End Sub
One works well for "Always on top feature" and other one for "Famous minimize button" when run separately, Is there any way, I could combine both of there two in a single code and hence i'll have both minimize button and always on top feature on same userform.
Any Help will be well Appreciated. Thanks in advance.
Bookmarks