Dave Punky
Board Regular
- Joined
- Jan 7, 2010
- Messages
- 133
Hi all,
I've been experimenting with minimizing a userform and I've encountered an issue which I know can be resolved, just not sure how to do it myself.
Basically I can add the minimize button but when it actually minimizes the window, I can't edit the worksheet I'm on or browse through any other open (or open) any additional workbooks. I'm thinking I need to separate off the instance of Excel using this userform as a starting point but I could be going on the wrong path.
Any ideas would help, and for your reference the code I'm using to accomplish this is below:
On Initialization of the form:
I've been experimenting with minimizing a userform and I've encountered an issue which I know can be resolved, just not sure how to do it myself.
Basically I can add the minimize button but when it actually minimizes the window, I can't edit the worksheet I'm on or browse through any other open (or open) any additional workbooks. I'm thinking I need to separate off the instance of Excel using this userform as a starting point but I could be going on the wrong path.
Any ideas would help, and for your reference the code I'm using to accomplish this is below:
Code:
Option Explicit
'Puts minimise and maximise buttons on form
'---------------------------------------
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLong _
Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong _
Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long
Private Const GWL_STYLE As Long = (-16)
Private Const WS_SYSMENU As Long = &H80000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const WS_MAXIMIZEBOX As Long = &H10000
'---------------------------------------
On Initialization of the form:
Code:
Private Sub UserForm_Initialize()
'# Puts minimise and maximise buttons on form
Dim Frmhdl As Long
Dim lStyle As Long
Frmhdl = FindWindow(vbNullString, Me.Caption)
lStyle = GetWindowLong(Frmhdl, GWL_STYLE)
lStyle = lStyle Or WS_SYSMENU
lStyle = lStyle Or WS_MINIMIZEBOX
' lStyle = lStyle Or WS_MAXIMIZEBOX '< Disabled Maximise
SetWindowLong Frmhdl, GWL_STYLE, (lStyle)
DrawMenuBar Frmhdl
End Sub