A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

An Easy Question: How to get a "msgbox" to display?



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old March 29th 06, 10:19 PM posted to microsoft.public.outlook.program_vba
Bernie
external usenet poster
 
Posts: 5
Default An Easy Question: How to get a "msgbox" to display?

Since I am not any great Visual Basic for Applications (VBA) programmer
I am probably missing something very simple here. I searched for an
answer in this group and some items that sound related don't seem to
apply to my problem.

So here it is...

I have a VBA program in an Excel spreadsheet. This program is creating
contacts in an Outlook folder and also putting some data in a worksheet
as it goes along. This program works great.

The little issue is under some conditions the program needs to issue a
message for the person to acknowledge (OK or CANCEL). The message box
does get generated but it does NOT display directly. The Outlook
window is the one that is opened at the time and if you don't notice it
the "Excel" on the task-bar is "blinking". You have to click on the
Excel application to get it to open and then you have the "msgbox"
being displayed.

I have tried to "activate" the Excel application but even in that case
the "msgbox"is not displayed unless I click on Excel.

So what is the trick I am missing? How do I get that "msgbox" to
display so my users don't have to "look for it"?

Thanks in advance for your help.

Bernie

  #2  
Old March 30th 06, 10:32 AM posted to microsoft.public.outlook.program_vba
Michael Bauer
external usenet poster
 
Posts: 435
Default An Easy Question: How to get a "msgbox" to display?

Am 29 Mar 2006 13:19:57 -0800 schrieb Bernie:

Bernie, the solution is not as simple as you might think.

You need to use some Win32 APIs to bring the windows into the foreground and
back again. While the Excel Application object exposes its window handle
Outlook doesn´t, so you need to find it yourself.

This sample (code in Excel) works if not Word is the e-mail editor:

Private Declare Function SetForegroundWindowA Lib "USER32" Alias
"SetForegroundWindow" (ByVal hwnd As Long) As Long
Private Declare Function FindWindow Lib "USER32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Function GetInspectorHandle(ByVal sCaption As String) As Long
GetInspectorHandle = FindWindow("rctrl_renwnd32", sCaption)
End Function

Sub test()
Dim app As Object
Dim mail As Object
Dim hnd As Long

Set app = GetObject(, "outlook.application")
Set mail = app.createitem(0)
mail.display

' get mail window´s handle
hnd = GetInspectorHandle(mail.GetInspector.Caption)

' bring excel into foreground
SetForegroundWindowA Application.hwnd

MsgBox "hallo"

' bring mail window into foreground again
SetForegroundWindowA hnd
End Sub


--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.vbOffice.net --


Since I am not any great Visual Basic for Applications (VBA) programmer
I am probably missing something very simple here. I searched for an
answer in this group and some items that sound related don't seem to
apply to my problem.

So here it is...

I have a VBA program in an Excel spreadsheet. This program is creating
contacts in an Outlook folder and also putting some data in a worksheet
as it goes along. This program works great.

The little issue is under some conditions the program needs to issue a
message for the person to acknowledge (OK or CANCEL). The message box
does get generated but it does NOT display directly. The Outlook
window is the one that is opened at the time and if you don't notice it
the "Excel" on the task-bar is "blinking". You have to click on the
Excel application to get it to open and then you have the "msgbox"
being displayed.

I have tried to "activate" the Excel application but even in that case
the "msgbox"is not displayed unless I click on Excel.

So what is the trick I am missing? How do I get that "msgbox" to
display so my users don't have to "look for it"?

Thanks in advance for your help.

Bernie

  #3  
Old March 30th 06, 08:55 PM posted to microsoft.public.outlook.program_vba
Bernie
external usenet poster
 
Posts: 5
Default An Easy Question: How to get a "msgbox" to display?

Thanks, Michael. I was sure hoping for something simple. But since
the concern is to move focus to Excel then we might not have to worry
about getting back to Outlook.

Thanks for the quick response....we will give it a try.

Bernie

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
An Easy Question: How to get a "msgbox" to display? Bernie Outlook and VBA 0 March 29th 06 10:19 PM
Outlook 2003\Exchange 2000 - "Unable to display the folder" in inbox TedStyle Outlook - Installation 0 March 13th 06 07:35 PM
How can I suppress annoying msgbox "enter network password"? maysider Outlook - Installation 2 February 16th 06 02:04 AM
"Display presence status in the from field" option won't stay sele Jim H Outlook - Installation 1 January 23rd 06 04:15 PM
Can I permanently change the default "display as" under email Foundation Mary Outlook - Using Contacts 1 January 12th 06 02:04 AM


All times are GMT +1. The time now is 10:39 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.