Msgbox

  • Thread starter Thread starter Bernd
  • Start date Start date
B

Bernd

Hi!
Is it possible to show a msgbox from Excel even if Excel is running in the
background?

Thanks for all hints (and codes).
Bernd
 
Hi Bernd

This will put a messagebox on top of whatever application you are using
(whith possible exceptions of other modal forms,messages or system dialogs).
Note that it's quite a nasty trick (about as annoying as Outlook's default
"You have mail" prompt) but I'm sure you will use this with care. Try the
Test macro, you will then have 8 seconds to switch to whatever app before
the messagebox shows up.

'********************************************
Option Explicit 'top of standard module

Declare Function GetForegroundWindow Lib _
"user32.dll" () As Long

Public 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

Sub MsgMe()
Dim x As Long
Dim y As Long
x = GetForegroundWindow
y = MessageBox(x, "My message", "Hi there", 65536)
End Sub

Sub test()
Application.OnTime _
(Now + TimeSerial(0, 0, 8)), "MsgMe"
End Sub
 
Hi Harald!

Phantastic! thanks a lot.

Bernd

Harald Staff said:
Hi Bernd

This will put a messagebox on top of whatever application you are using
(whith possible exceptions of other modal forms,messages or system dialogs).
Note that it's quite a nasty trick (about as annoying as Outlook's default
"You have mail" prompt) but I'm sure you will use this with care. Try the
Test macro, you will then have 8 seconds to switch to whatever app before
the messagebox shows up.

'********************************************
Option Explicit 'top of standard module

Declare Function GetForegroundWindow Lib _
"user32.dll" () As Long

Public 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

Sub MsgMe()
Dim x As Long
Dim y As Long
x = GetForegroundWindow
y = MessageBox(x, "My message", "Hi there", 65536)
End Sub

Sub test()
Application.OnTime _
(Now + TimeSerial(0, 0, 8)), "MsgMe"
End Sub
 
Upps! Nachtrag: Ist das auch mit einer Inputbox oder einem eigenen Formular
möglich?

Bernd
 
Ooops, in English! Addendum: is this also possible with inputboxes or forms?

best regards
Bernd
 
Back
Top