Microsoft Excel - Macros - Display - Show Excel on Top

Sub ShowXLOnTop(ByVal OnTop As Boolean)
 
    Dim xStype As Long
 
#If Win64 Then
    Dim xHwnd As LongPtr
#Else
    Dim xHwnd As Long
#End If
 
    If OnTop Then
        xStype = HWND_TOPMOST
    Else
        xStype = HWND_NOTOPMOST
    End If
 
    Call SetWindowPos(Application.hwnd, xStype, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
 
End Sub
 
 
' Sets that XL is the top window of all applications.
Sub SetXLOnTop()
    ShowXLOnTop True
End Sub
 
 
' Sets that XL is not necessarily the top windows of all applications.
' If this were not run at some stage then no other application, such as mail, would be able to be seen.
Sub SetXLNormal()
    ShowXLOnTop False
End Sub