I have an HTA application that launches Outlook's Global Address List (GAL) so that the user can easily pick an email recipient from our company directory. However, when launched the GAL window is not brought to the front of the screen. It is displayed behind the HTA.
Here's my code. Is there a way to bring the GAL to the front (or move the HTA to the back)?
<HEAD>
<!---------------Resize & Move Window------------------------------>
<script language="vbscript">
window.resizeto 400, 300
screenWidth = Document.ParentWindow.Screen.AvailWidth
screenHeight = Document.ParentWindow.Screen.AvailHeight
posLeft = (screenWidth - 400) / 2
posTop = (screenHeight - 300) / 2
window.moveTo posLeft, posTop
</script>
<!---------------Application Info---------------------------------->
<TITLE>GAL Picker</TITLE>
<HTA:APPLICATION ID="MyApp"
APPLICATIONNAME="My GAL Picker"
BORDER="Dialog"
CAPTION="Yes"
SCROLL="no"
MAXIMIZEBUTTON="Yes"
MINIMIZEBUTTON="Yes"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="no"
SYSMENU="Yes">
</HEAD>
<BODY>
<body STYLE="font:12 pt arial; color:white;
filter:progid:DXImageTransform.Microsoft.Gradient
(GradientType=0, StartColorStr='#000000', EndColorStr='#0000FF')">
<SCRIPT LANGUAGE="VBScript">
'''''''''''''''''''''SUBS''''''''''''''''''''''''''''''''''''''''''''
Sub GALPicker
Dim objWordApp
Dim strEmailName
Set objWordApp = CreateObject("Word.Application")
strAddress = objWordApp.GetAddress(, "<PR_DISPLAY_NAME>", False, 1, 1, , True, True)
If strAddress = "" Then
Exit Sub
Else
End If
msgbox strAddress
MyGal.Value = strAddress
End Sub
</SCRIPT>
<H2>My Outlook GAL Picker</H2>
<P>Add Email Recipient:
<input type="text" name="MyGAL" size="30" onfocus="vbscript:Call GALPicker">
Here's a sample of using AppActivate
in a second script so that it doesn't block your main script.
In your main script:
' Call a second script (asynchronously) to activate the window...
CreateObject("WScript.Shell").Run "activate.vbs", 0, False
' Now load our GAL window...
strAddress = objWordApp.GetAddress(...)
The second script (activate.vbs
) would look like this:
Set Shell = CreateObject("WScript.Shell")
' Try to activate the GAL window for 10 attempts/seconds...
For i = 1 To 10
If Shell.AppActivate("Select Name") Then Exit For
WScript.Sleep 1000
Next
So we kick off the second script and then continue on with the loading of the GAL "Select Name" window. The second script will try 10 times (waiting a second between each attempt) to see if it can find the "Select Name" window and, if it does, it will activate it.
It's a bit of a hack but it just might work!