VBA激活Internet Explorer窗口 [英] VBA to Activate Internet Explorer Window
问题描述
我正在制作一个宏,用于打开Internet Explorer,导航并登录到网站.一切正常,但是我需要提前启用IE窗口并激活它,因此可以在其上使用 SendKeys
.我在名为 AppActivate
的命令上找到了使用不同方法的网站和视频,并且我已经尝试了很多方法,但是即使我复制了整个代码(对作者有效),也不会为我工作,我总是收到一个错误:无效的过程调用或参数-错误5
I'm making a macro that opens Internet Explorer, navigates and logs into a website. Everything works fine, but I need to bring the IE Window up front, and activate it, so I can use SendKeys
on it.
I've found websites and videos with different approaches on a command called AppActivate
and i've tried many of them, but even if I copy the entire code (which works for the author) it won't work for me, I always get an error: Invalid Procedure Call or Argument - Error 5
我找到并尝试过的所有内容的列表:
A list of everything I've found and tried:
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配合使用.
observations: I'm running this inside Excel 2013 and I'm using Windows 7 with IE 11.
推荐答案
我总是将IE设为无类型对象,就像这样
I always just make IE an untyped object, like so
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窗口将具有焦点.
The IE window has focus when this finishes running on my end.
这篇关于VBA激活Internet Explorer窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!