' Window API Declarations ' These Declares MUST appear at the top of the code module, above and before any VBA procedures. 'Const HWND_BOTTOM = 1 Const SWP_NOSIZE = &H1 Const SWP_NOMOVE = &H2 Const SWP_NOACTIVATE = &H10 Const SWP_SHOWWINDOW = &H40 Public Const HWND_TOPMOST = -1 Public Const HWND_NOTOPMOST = -2 Public Const HWND_TOP = 0 Public Const HWND_BOTTOM = 1 ' http://www.tek-tips.com/faqs.cfm?fid=4699 ' ' Message boxes are always modal, which means that the underlying application (e.g. Excel) waits for a response from ' the User and does not allow any other interaction until one is given. ' By default they are application modal (they remain in front of all other windows belonging to the owning application ' but have no impact on other applications), but they may also be system modal (they remain in front of ALL other ' windows although they have no non-visual impact on applications other than the owning one). ' ' Use the Message Box facility directly, via the Windows API, instead of via the VBA interface. ' Using it is pretty much the same as using MsgBox, except that you have the opportunity to set some parameter values ' which are defaulted in the VBA interface, in particular the message box, although technically still modal, can be ' attached to any window, or none. If you do not attach it to your window, it will not restrict your User's interaction ' with the application. Private Declare Function MessageBox _ Lib "user32" Alias "MessageBoxA" _ (ByVal hwnd As Long, _ ByVal lpText As String, _ ByVal lpCaption As String, _ ByVal wType As Long) _ As Long ' Used to have XL be on top of all other windows. #If Win64 Then Public Declare PtrSafe Function SetWindowPos _ Lib "user32" ( _ ByVal hwnd As LongPtr, _ ByVal hwndInsertAfter As LongPtr, _ ByVal x As Long, _ ByVal y As Long, _ ByVal cx As Long, _ ByVal cy As Long, _ ByVal wFlags As Long) _ As Long #Else Public 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 #End If