Vbscript HTA,Outlook全局地址列表,带到前面
我有一个HTA应用程序,可以启动Outlook的全局地址列表(GAL),这样用户就可以轻松地从公司目录中选择电子邮件收件人。但是,当启动GAL窗口时,GAL窗口不会显示在屏幕的前面。它显示在HTA后面 这是我的密码。是否有办法将GAL移到前面(或将HTA移到后面)Vbscript HTA,Outlook全局地址列表,带到前面,vbscript,back,hta,gal,Vbscript,Back,Hta,Gal,我有一个HTA应用程序,可以启动Outlook的全局地址列表(GAL),这样用户就可以轻松地从公司目录中选择电子邮件收件人。但是,当启动GAL窗口时,GAL窗口不会显示在屏幕的前面。它显示在HTA后面 这是我的密码。是否有办法将GAL移到前面(或将HTA移到后面) window.resizeto 400、300 screenWidth=Document.ParentWindow.Screen.AvailWidth 屏幕高度=Document.ParentWindow.Screen.AvailH
window.resizeto 400、300
screenWidth=Document.ParentWindow.Screen.AvailWidth
屏幕高度=Document.ParentWindow.Screen.AvailHeight
posLeft=(屏幕宽度-400)/2
posTop=(屏幕高度-300)/2
window.movetoposleft,posTop
半乳糖采摘器
潜水艇
副检流计
Dim objWordApp
暗号
设置objWordApp=CreateObject(“Word.Application”)
StradAddress=objWordApp.GetAddress(,“”,False,1,1,True,True)
如果strAddress=“”,则
出口接头
其他的
如果结束
msgbox Strad连衣裙
MyGal.Value=0
端接头
我的女拾荒者
添加电子邮件收件人:
下面是在第二个脚本中使用AppActivate
的示例,这样它就不会阻塞主脚本
在主脚本中:
' 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(...)
第二个脚本(activate.vbs
)如下所示:
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
因此,我们启动第二个脚本,然后继续加载GAL“selectname”窗口。第二个脚本将尝试10次(每次尝试之间等待一秒钟),以查看是否可以找到“选择名称”窗口,如果可以,它将激活该窗口
这是一个有点黑客,但它可能会工作 以下是我最后要做的事情,以供将来参考
<HEAD>
<!---------------Resize & Move Window------------------------------>
<script language="vbscript">
window.resizeto 460,255
screenWidth = Document.ParentWindow.Screen.AvailWidth
screenHeight = Document.ParentWindow.Screen.AvailHeight
posLeft = (screenWidth - 460) / 2
posTop = (screenHeight - 255) / 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")
'new line of code proviced by Bond, adjust file path as needed
CreateObject("WScript.Shell").Run "C:\Users\JohnDoe\Desktop\activate.vbs", 0, False
strAddress = objWordApp.GetAddress(, "<PR_EMAIL_ADDRESS>" & " ### " & "<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="testGAL" id= "MyGALTest" size="36" onfocus="vbscript:Call GALPicker">
您是否尝试过使用
AppActivate
?是。今天我尝试使用:Set WshShell=CreateObject(“WScript.Shell”)WshShell.AppActivate“选择名称”。但不管我把它放在代码的什么地方,它都不会把Outlook GAL拉到前面。我相信这是因为代码在这行代码上暂停用户输入:strAddress=objWordApp.GetAddress(,“”,False,1,1,True,True)。您可以从第一个脚本调用使用AppActivate
的第二个脚本。这样,它就不会被GetAddress
阻止。您的第二个脚本可能会循环,直到AppActivate
返回True
(或者直到出现某种超时)。您能否再解释一下如何修改脚本以使其正常工作?我尝试调用第二个脚本,但Outlook GAL在运行其余脚本之前仍会暂停等待用户输入。我将添加它作为答案,以便代码更具可读性。太好了,谢谢!我明白你的意思。这很有效。谢谢你的帮助!看起来不错。我看到你把睡眠时间改成了100毫秒。只需知道,在放弃之前,您的脚本只会在“选择名称”窗口中查找1秒(100ms*10次迭代)。如果您发现您的窗口不再被激活,请尝试增加此循环中的迭代次数和/或睡眠时间。
<HEAD>
<!---------------Resize & Move Window------------------------------>
<script language="vbscript">
window.resizeto 460,255
screenWidth = Document.ParentWindow.Screen.AvailWidth
screenHeight = Document.ParentWindow.Screen.AvailHeight
posLeft = (screenWidth - 460) / 2
posTop = (screenHeight - 255) / 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")
'new line of code proviced by Bond, adjust file path as needed
CreateObject("WScript.Shell").Run "C:\Users\JohnDoe\Desktop\activate.vbs", 0, False
strAddress = objWordApp.GetAddress(, "<PR_EMAIL_ADDRESS>" & " ### " & "<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="testGAL" id= "MyGALTest" size="36" onfocus="vbscript:Call GALPicker">
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 100
Next