VBA minimising Forms

Nimbo1842

New member
Local time
Today, 19:04
Joined
Mar 17, 2013
Messages
8
Morning,

I currently have Excel 2007 at home but run 2003 at work the below code works brilliant to enable a form to minimise onto the windows toolbar and back again with 2007. However when I take it to work on 2003 it does work, basically when you minimise the form it does not appear on the windows toolbar. If you cycle through using ALT/TAB then it appears as a icon and can be selected.

Can anyone see why it does not appear on the windows toolbar in 2003?

Option Explicit
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 Declare Function FindWindowA _
Lib "user32" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long
Private Const GWL_EXSTYLE = (-20)
Private Const GWL_STYLE As Long = (-16)
Private Const WS_EX_APPWINDOW = &H40000
Private Const WS_SYSMENU As Long = &H80000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const WS_MAXIMIZEBOX As Long = &H10000

Private Sub UserForm_Activate()
Dim lFrmWndHdl As Long
Dim lStyle As Long
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
lFrmWndHdl = FindWindowA("ThunderDFrame", Me.Caption)
lStyle = GetWindowLong(lFrmWndHdl, GWL_STYLE)
lStyle = lStyle Or WS_SYSMENU
lStyle = lStyle Or WS_MINIMIZEBOX
'lStyle = lStyle Or WS_MAXIMIZEBOX
SetWindowLong lFrmWndHdl, GWL_STYLE, (lStyle)
lStyle = GetWindowLong(lFrmWndHdl, GWL_EXSTYLE)
lStyle = lStyle Or WS_EX_APPWINDOW
SetWindowLong lFrmWndHdl, GWL_EXSTYLE, lStyle
DrawMenuBar lFrmWndHdl
'AppActivate ("Microsoft Excel")
ThisWorkbook.Application.Visible = True
ThisWorkbook.Application.Visible = False
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True
End Sub
 

Users who are viewing this thread

Back
Top Bottom