I managed to get Excel 2007 starting in fullscreen with help from the following link on this forum: http://www.mrexcel.com/forum/showthread.php?t=333929
But when i want to close excel, i want everything restored to default. Showing all toolbars
again at startup when I open another file. Problem is that I couldn't manage this with the same code.
It only shows the title bar on startup, but not all commandbars on the quick access toolbar, it's as if
excel doesn't update before save. When i click on the minimize and maximize button,
the total toolbar shows up again :S
Can anyone break this code down into a startup in fullscreen and close the file with all toolbars en titlebar shown again.
Thanks for all the help.
But when i want to close excel, i want everything restored to default. Showing all toolbars
again at startup when I open another file. Problem is that I couldn't manage this with the same code.
It only shows the title bar on startup, but not all commandbars on the quick access toolbar, it's as if
excel doesn't update before save. When i click on the minimize and maximize button,
the total toolbar shows up again :S
Can anyone break this code down into a startup in fullscreen and close the file with all toolbars en titlebar shown again.
Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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 GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const WS_CAPTION = &HC00000
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_SYSMENU = &H80000
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 Enum ESetWindowPosStyles
SWP_SHOWWINDOW = &H40
SWP_HIDEWINDOW = &H80
SWP_FRAMECHANGED = &H20
SWP_NOACTIVATE = &H10
SWP_NOCOPYBITS = &H100
SWP_NOMOVE = &H2
SWP_NOOWNERZORDER = &H200
SWP_NOREDRAW = &H8
SWP_NOREPOSITION = SWP_NOOWNERZORDER
SWP_NOSIZE = &H1
SWP_NOZORDER = &H4
SWP_DRAWFRAME = SWP_FRAMECHANGED
HWND_NOTOPMOST = -2
End Enum
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Sub Title_Toggle()
ShowTitleBar Application.DisplayFullScreen
End Sub
Sub ShowTitleBar(bShow As Boolean)
Dim lStyle As Long
Dim tRect As RECT
Dim sWndTitle As String
Dim xlhnd
'// Find window handle
sWndTitle = Application.Caption '// Old code used "Microsoft Excel - " & ActiveWindow.Caption
xlhnd = FindWindow("XLMAIN", sWndTitle) '// Old code did not have class name
'// Get the window's position:
GetWindowRect xlhnd, tRect
'// Show the Title bar ?
If Not bShow Then
lStyle = GetWindowLong(xlhnd, GWL_STYLE)
lStyle = lStyle And Not WS_SYSMENU
lStyle = lStyle And Not WS_MAXIMIZEBOX
lStyle = lStyle And Not WS_MINIMIZEBOX
lStyle = lStyle And Not WS_CAPTION
Else
lStyle = GetWindowLong(xlhnd, GWL_STYLE)
lStyle = lStyle Or WS_SYSMENU
lStyle = lStyle Or WS_MAXIMIZEBOX
lStyle = lStyle Or WS_MINIMIZEBOX
lStyle = lStyle Or WS_CAPTION
End If
SetWindowLong xlhnd, GWL_STYLE, lStyle
Application.DisplayFullScreen = Not bShow
'// Ensure the style is set and makes the xlwindow the
'// same size, regardless of the title bar.
SetWindowPos xlhnd, 0, tRect.Left, tRect.Top, tRect.Right - tRect.Left, tRect.Bottom - tRect.Top, SWP_NOREPOSITION Or SWP_NOZORDER Or SWP_FRAMECHANGED
End Sub
Thanks for all the help.