![](/img/trans.png)
[英]How to navigate to an already opened internet explorer window? (VBA)
[英]How to navigate to an already opened IE window using vba?
所以我一直在嘗試使用VBA導航到已打開的IE窗口。 我發現了一篇帖子,解釋了如何做到這一點。 但是,我現在的主要問題是我不太熟悉VBA,特別是我的網站,似乎沒有文檔標題。 當我在調試器中檢查它時,我在html代碼中的所有內容如下:
<title></title>
我在這里錯過了什么嗎? 有沒有其他方式來引用可能更簡單或更簡單的網站?
Sub demo()
Dim str_val As Object
marker = 0
Set objShell = CreateObject("Shell.Application")
IE_count = objShell.Windows.Count
For x = 0 To (IE_count - 1)
On Error Resume Next
my_url = objShell.Windows(x).document.Location
my_title = objShell.Windows(x).document.Title
If my_title Like "XYZ" & "*" Then
Set IE = objShell.Windows(x)
marker = 1
Exit For
Else
End If
Next
If marker = 0 Then
MsgBox ("A matching webpage was NOT found")
Else
MsgBox ("A matching webpage was found")
Set str_val = IE.document.getElementById("txtbox1")
str_val.Value = "demo text"
End If
End Sub
VBA代碼與已經打開的特定IE窗口進行交互
這是我通常處理上述問題的方式,
Sub GetURLs()
' Uses MS HTML Controls
' and MS Internet Controls
Dim s As SHDocVw.InternetExplorer
Dim sw As SHDocVw.ShellWindows
Dim d As MSHTML.HTMLDocument
Set sw = New SHDocVw.ShellWindows
For Each s In sw
If TypeName(s) = "IWebBrowser2" And s.Name <> "Windows Explorer" Then
Debug.Print s.Name, s.LocationURL
Set d = s.Document
Debug.Print d.getElementsByTagName("TD")(0).innerhtml
End If
Next s
Set sw = Nothing
Set s = Nothing
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.