【发布时间】:2019-03-12 18:49:53
【问题描述】:
所以我在网上搜索了很多关于如何执行此操作的信息,但似乎找不到任何具体信息。我看过很多关于如何打开新的 Internet Explorer 窗口并导航到特定网站的示例。但是,在我的特定情况下,我希望能够简单地导航到已经打开的 Internet Explorer 窗口(这将是 Internet Explorer 中唯一打开的窗口/选项卡)。这样做的原因是因为每次我打开网站时,我都需要先登录才能做任何事情。然后,理想情况下,我想将一些 ID 粘贴到搜索框中并按 Enter(我应该能够通过在线搜索了解如何执行此部分)。
这是我目前发现的,但我有点迷茫,不知道如何应用这段代码来按我的意愿工作。
Sub ExplorerTest()
Const myPageTitle As String = "Wikipedia"
Const myPageURL As String = "http://en.wikipedia.org/wiki/Main_Page"
Const mySearchForm As String = "searchform"
Const mySearchInput As String = "searchInput"
Const mySearchTerm As String = "Document Object Model"
Const myButton As String = "Go"
Dim myIE As SHDocVw.InternetExplorer
With myIE.Document.forms(mySearchForm)
'enter search term in text field
.elements(mySearchInput).Value = mySearchTerm
'press button "Go"
.elements(myButton).Click
End With
End Sub
【问题讨论】:
-
您可以自动登录
-
好吧,我明白了。但是,我不会是唯一使用该宏的人,因此出于安全原因,我也无法自动登录其他人。
-
Op 为同一问题创建了一个 [重复线程]。参考:stackoverflow.com/questions/55164307/…
标签: excel vba internet-explorer