Thanks to shg and dredwolf for testing it in 2007. Both could not replicate the problem. Additionally, shg instructed me on how to reverse the process which I didn't know was possible.
Updated code is as follows:
ThisWorkbook:
Option Explicit
Private Sub Workbook_Open()
With Application
Closing = False
.ScreenUpdating = False
.Run "RemoveBorder"
End With
End Sub
Private Sub Workbook_Activate()
With Application
.ScreenUpdating = False
.Run "RemoveBorder"
End With
End Sub
Private Sub Workbook_Deactivate()
With Application
.ScreenUpdating = False
.Run "RemoveBorder"
End With
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
With Application
Closing = True
.ScreenUpdating = True
.Run "RemoveBorder"
End With
End Sub
Standard module:
Option Explicit
Public Closing As Boolean
Const GWL_STYLE = (-16)
Const WS_BORDER = &H80000
#If VBA7 Then
Private Declare PtrSafe Function GetWindowLongPtr Lib "User32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare PtrSafe Function SetWindowLongPtr Lib "User32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
#Else
Private Declare Function GetWindowLongPtr Lib "User32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLongPtr Lib "User32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
#End If
Private Sub RemoveBorder()
Dim hWnd As Long, style As Long, ret As Long
Application.WindowState = xlMaximized
hWnd = Application.hWnd
If ActiveWorkbook.Name = ThisWorkbook.Name And Closing = False Then
style = GetWindowLongPtr(hWnd, GWL_STYLE)
style = style And Not (WS_BORDER)
ret = SetWindowLongPtr(hWnd, GWL_STYLE, style)
Else
style = GetWindowLongPtr(hWnd, GWL_STYLE) Or WS_BORDER
ret = SetWindowLongPtr(hWnd, GWL_STYLE, style)
End If
End Sub
Now the two lines after "#Else" will be red because you are running Office 2007, but it should still compile normally.
Hopefully this time around will it work.
abousetta
Bookmarks