将程序带到前面的VBS脚本

时间:2012-10-26 19:25:09

标签: button vbscript click window

我正在编写VBS代码以打开Internet Explorer并访问www.google.com但是当我运行该程序时,它会打开并导航到www.yahoo.com但是Internet Explorer不是前台窗口。谁能帮我这个?有没有我可以使用的代码将Internet Explorer带到前面?谢谢你们!这是我的代码:

Option Explicit
 Dim ie


Set ie = CreateObject("InternetExplorer.Application")

ie.Navigate("wwww.yahoo.com")

最后一个问题 - 是否有一个代码可以用来点击某个按钮 - 特别是按“标签”我无法访问的按钮?

谢谢大家!

3 个答案:

答案 0 :(得分:2)

试试这个:

Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "http://www.yahoo.com/"
Do While ie.Busy : WScript.Sleep 100 : Loop
ie.Visible = True
CreateObject("WScript.Shell").AppActivate ie.document.title

答案 1 :(得分:2)

我发现在调用AppActivate方法 之后将Visible属性设置为True 是@ daniel-cook。

因此,简单地交换@ ansgar-wiechers示例中的最后两行会产生所需的结果。

Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "http://www.yahoo.com/"
Do While ie.Busy : WScript.Sleep 100 : Loop
CreateObject("WScript.Shell").AppActivate ie.document.title
ie.Visible = True

答案 2 :(得分:0)

这可以在我的计算机上打开IE并加载www.google.com:

Dim oShell
Set oShell = CreateObject("WScript.Shell")
oShell.Run ("iexplore www.google.com")

关于你的上一个问题......可能,但你需要更具体,并且应该提出另一个问题。