VBA激活Internet Explorer窗口

时间:2017-09-01 18:46:00

标签: excel vba excel-vba

我正在创建一个打开Internet Explorer的宏,导航并登录到网站。一切正常,但我需要预先启用IE窗口并激活它,这样我就可以使用SendKeys了。 我在名为AppActivate的命令中找到了不同方法的网站和视频,我尝试了很多,但即使我复制了整个代码(适用于作者),它对我也无效,我总是得到一个错误:无效的过程调用或参数 - 错误5

我找到并尝试的所有内容的列表:

Dim objIE As InternetExplorerMedium
Set objIE = New InternetExplorerMedium
objIE.navigate "http://google.com"
'makes it visible, but not active
objIE.Visible = True

'A list of ways I've tried:
objIE.AppActivate "Google - Internet Explorer"
AppActivate "Google - internet Explorer"
'the above supposedly looks for the title of the page
AppActivate objIE
AppActivate (objIE)
AppActivate "objIE"

观察:我在Excel 2013中运行它,我正在使用Windows 7和IE 11。

1 个答案:

答案 0 :(得分:1)

我总是让IE成为无类型对象,就像这样

Sub test()
Dim IE As Object

Set IE = Nothing
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "www.google.com"
IE.Visible = True

End Sub

当IE窗口在我的终点上运行时,它会有焦点。

相关问题