[英]VBA Excel input data into already opened ie window
我在这里有一个非常简单的例子,当按下button1将打开一个新的窗口并进入谷歌搜索输入“便宜的塑料窗口”。 我想要做的是当我按下按钮2谷歌搜索(已打开即窗口)中的文本更改为“便宜的塑料门”。 我一直试图做2天,但似乎无法找到如何。 如果你能帮助一个有效的例子,我将不胜感激。 谢谢
Private Sub CommandButton1_Click()
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Navigate ("www.google.co.uk")
Do
DoEvents
Loop Until objIE.ReadyState = 4
objIE.Document.GetElementById("lst-ib").Value = "cheap plastic windows"
End Sub
Private Sub CommandButton2_Click()
'the command below does not as obviously the objIE is not select which I have no idea how to do
ie.Document.GetElementById("lst-ib").Value = "cheap plastic doors"
End Sub
您可以使用它来检查以确保窗口在那里,如果是这样,它会找到它并在其中键入。 如果用户在单击“CommandButton2”之前转到另一个应用程序可能无法正常工作,则存在一个小风险。 但是如果用户只停留在您的宏和IE上,它就会起作用。
Private Sub CommandButton2_Click()
Dim ie As Object
With CreateObject("Shell.Application").Windows
If .Count > 0 Then
' Get IE
Set ie = .Item(.Count - 1)
Else
' Create IE
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
End If
End With
ie.Document.GetElementById("lst-ib").Value = "cheap plastic doors"
Set ie = Nothing
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.