我这里有一个非常简单的例子,当按下button1将打开一个新的ie窗口,并进入谷歌搜索输入“廉价塑料窗口”。我想做的是,当我按下button2时,google中的文字(已经打开ie窗口)变成了“廉价塑料门”。我已经试了两天了,但似乎找不到该怎么做。如果你能帮我举个例子,我会很感激的。谢谢
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发布于 2016-09-30 16:35:50
您可以使用它,它检查窗口是否在那里,如果是这样的话,它会找到它并在其中键入。如果用户在单击"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 Subhttps://stackoverflow.com/questions/39794951
复制相似问题