如何在文本区域输入数据并单击搜索按钮

时间:2016-11-24 02:40:12

标签: vba

我正在尝试填充文本区域并单击Web工具上的搜索按钮。我写了下面的代码,但它只是打开了工具。但是,不填写文本区域。

以下是我的代码:

Sub PLCbot()
Dim myvalue As String
Dim myie As Object
Dim myloop As Object
Dim myelements As Object
Dim wksheet As Worksheet
Dim Workbook As Workbook

myvalue = Worksheets("Sheet1").Range("A1").Value

Set myie = CreateObject("Internetexplorer.Application")
myie.Visible = True
myie.Navigate2 "http://psrhpinc.usa.hp.com/wplc/SalesMarketingView.aspx?ViewOption=SalesMarket"
Do While myie.Busy
Loop

Set myelements = myie.document.getElementsByTagName("textarea")
For Each myloop In myelements
If myloop.Name = "textarea" Then

myloop.Value = myvalue
End If
Exit For
Next

End Sub

1 个答案:

答案 0 :(得分:0)

Exit For应位于If-End If内。请尝试以下

For Each myloop In myelements
    If myloop.Name = "textarea" Then
        myloop.Value = myvalue
        Exit For
    End If  
Next