Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VBA Excel将数据输入已打开的ie窗口_Excel_Vba - Fatal编程技术网

VBA Excel将数据输入已打开的ie窗口

VBA Excel将数据输入已打开的ie窗口,excel,vba,Excel,Vba,我这里有一个非常简单的例子,按下按钮1将打开一个新的ie窗口,进入谷歌搜索输入“廉价塑料窗口”。我想做的是当我按下按钮2时,谷歌搜索(已经打开ie窗口)中的文本变为“廉价塑料门”。我已经试了两天了,但似乎找不到方法。如果您能提供一个工作示例,我将不胜感激。多谢各位 Private Sub CommandButton1_Click() Set objIE = CreateObject("InternetExplorer.Application") objIE.Visible = True o

我这里有一个非常简单的例子,按下按钮1将打开一个新的ie窗口,进入谷歌搜索输入“廉价塑料窗口”。我想做的是当我按下按钮2时,谷歌搜索(已经打开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

您可以使用它来检查窗口是否存在,如果存在,它会找到并在其中键入。如果用户在单击“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

您可以使用它来检查窗口是否存在,如果存在,它会找到并在其中键入。如果用户在单击“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

谢谢你的回答!在你发布之前,我在网上找到了一个示例,它也很有效。最后,我可以继续我的项目,因为我被困了近2天:)谢谢你的回答!在你发布之前,我在网上找到了一个示例,它也很有效。最后,我可以继续我正在工作的项目,因为它被困了近2天:)