#If VBA7 Then
Private Declare PtrSafe Function GetWindowRect Lib "user32" (ByVal hwnd As LongPtr, lpRect As RECT) As Long
#Else
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
#End If
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
'-----------------
'Window Exact RECT
'-----------------
Private Function GetWindowExactRECT(Window As Window) As RECT
Dim R As RECT
Dim MaximizedDelta As Long
Call GetWindowRECT(Window.hwnd, R)
With R
If Window.WindowState = xlMaximized Then
'Depending on the TaskBar position and presence
If .Left < 0 Then
MaximizedDelta = .Left
ElseIf .Top < 0 Then
MaximizedDelta = .Top
End If
.Left = .Left - MaximizedDelta
.Top = .Top - MaximizedDelta
.Right = .Right + MaximizedDelta
.Bottom = .Bottom + MaximizedDelta
End If
End With
'Return value
GetWindowExactRECT = R
End Function