make msgbox appear on top of all other (1 Viewer)

smiler44

Registered User.
Local time
Today, 01:16
Joined
Jul 15, 2008
Messages
641
I would like my message boxes to appear on top of all other windows. Excel will probably be minimized but I do need the message box to appear on top of things like Internet Explorer.

smiler44
 

boblarson

Smeghead
Local time
Yesterday, 17:16
Joined
Jan 12, 2001
Messages
32,059
Sorry, it won't happen. Message boxes from within an Office program are only available while in that container. So, the Excel application container needs to be up for you to see any message boxes that were generated from Excel/Excel VBA. And the same goes for Word, PowerPoint, Visio, and Access.
 

smiler44

Registered User.
Local time
Today, 01:16
Joined
Jul 15, 2008
Messages
641
Bob I think I've collapsed with shock but thank you for such a quick reply. I've spent hours this week creating a new project only to fall or perhaps only stumble at the last fence.

mmm I'll have to rethink how to bring users attention to an event that is soon to happen. Can I get Excel to pop up on top perhaps from a minimized position thus allowing the message box to appear on top? I'm sure I've read somewhere that it is possible to make the screen "shake" but thats a bit dramatic.

smiler44
 

darbid

Registered User.
Local time
Today, 02:16
Joined
Jun 26, 2008
Messages
1,428
I have not tested this to know if you can bring it to the front but maybe you could call the Win32 API. MessageBox which might then work independant of your Office Application.

Otherwise when I am working with Access and Outlook and I want a message from Access to be seen I give access the focus first like this -

Code:
SetForegroundWindow Application.hWndAccessApp
fSetAccessWindow (SW_SHOWMAXIMIZED)
Code:
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Code:
Function fSetAccessWindow(nCmdShow As Long)
'Usage Examples
'Maximize window:
'       ?fSetAccessWindow(SW_SHOWMAXIMIZED)
'Minimize window:
'       ?fSetAccessWindow(SW_SHOWMINIMIZED)
'Hide window:
'       ?fSetAccessWindow(SW_HIDE)
'Normal window:
'       ?fSetAccessWindow(SW_SHOWNORMAL)
'
Dim loX  As Long
Dim loForm As Form
    On Error Resume Next
    Set loForm = Screen.ActiveForm
    If Err <> 0 Then 'no Activeform
      If nCmdShow = SW_HIDE Then
        MsgBox "Cannot hide Access unless " _
                    & "a form is on screen"
      Else
        loX = apiShowWindow(hWndAccessApp, nCmdShow)
        Err.Clear
      End If
    Else
        If nCmdShow = SW_SHOWMINIMIZED And loForm.Modal = True Then
            MsgBox "Cannot minimize Access with " _
                    & (loForm.Caption + " ") _
                    & "form on screen"
        ElseIf nCmdShow = SW_HIDE And loForm.PopUp <> True Then
            MsgBox "Cannot hide Access with " _
                    & (loForm.Caption + " ") _
                    & "form on screen"
        Else
            loX = apiShowWindow(hWndAccessApp, nCmdShow)
        End If
    End If
    fSetAccessWindow = (loX <> 0)
End Function
 

smiler44

Registered User.
Local time
Today, 01:16
Joined
Jul 15, 2008
Messages
641
darbid, this looks massively complicated but I'll check it out, thank you.

A work around I found seems to be to make sure some of the desktop is visible, when excel then comes from minimised it is on top of everything else.

smiler44
 

darbid

Registered User.
Local time
Today, 02:16
Joined
Jun 26, 2008
Messages
1,428
darbid, this looks massively complicated but I'll check it out, thank you.

Agreed! It was for me when I needed it, but as I made it a public function I am amazed how often I am now using it when I automate the office programs.
 

Users who are viewing this thread

Top Bottom