Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.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
Excel 如何从网页中获取价值?_Excel_Vba_Web - Fatal编程技术网

Excel 如何从网页中获取价值?

Excel 如何从网页中获取价值?,excel,vba,web,Excel,Vba,Web,我想获取/输入网页的值 到目前为止,我所有的努力都只在web加载之前起作用。我不懂网络。我不能提供网站链接,因为它是一个内部网 done lin.e 50是我想输入的地方 然后单击保存按钮 <td valign="top" class="s bgltgray"> <textarea id="txtResponse1" name="txtResponse1" cols="80" rows="3" class="s">done lin.e 50.</textar

我想获取/输入网页的值

到目前为止,我所有的努力都只在web加载之前起作用。我不懂网络。我不能提供网站链接,因为它是一个内部网

done lin.e 50
是我想输入的地方

然后单击
保存按钮

<td valign="top" class="s bgltgray">
    <textarea id="txtResponse1" name="txtResponse1" cols="80" rows="3" class="s">done lin.e 50.</textarea>
    <input type="submit" id="cmdRespond1" name="cmdRespond1" value="Save" onclick="cmdRespond_click(1);">
    <br> Latest Response By: samyvelu, On: 10/23/2017
</td>

完成,林·e·50。

最新回复:samyvelu,日期:2017年10月23日
您可以试试这个。无法真正测试它,因为我没有url,但这段代码在没有textarea标记名的另一个url上工作

Sub IEtest()
Dim ie As Object
Dim i, x As Integer
Dim objElement As Object
Dim objCollection As Object

Set ie = CreateObject("InternetExplorer.Application")
With ie
    .Visible = True
    .navigate "" '<--- CHANGE THIS

    Do While ie.busy
        Application.Wait DateAdd("s", 1, Now)
    Loop

    Set objCollection = ie.Document.getElementsByTagName("textarea")

    i = 0

    While i < objCollection.Length
        If objCollection(i).Name = "txtResponse1" Then
            objCollection(i).Value = "Your input" '<--- CHANGE THIS
        End If
        i = i + 1
    Wend

    Set objCollection = ie.Document.getElementsByTagName("input")

    i = 0

    While i < objCollection.Length

        If objCollection(i).Type = "submit" And objCollection(i).Name = "cmdRespond1" Then
            Set objElement = objCollection(i)
        End If
        i = i + 1
    Wend

    objElement.Click
End With
End Sub
Sub-IEtest()
模糊的物体
Dim i,x为整数
作为对象的模糊对象
作为对象的Dim OBJ集合
设置ie=CreateObject(“InternetExplorer.Application”)
与ie
.Visible=True

.navigate“”存在ID。使用这些方法,因为它们是最快的选择器方法。使用InternetExplorerMedium对象

With ie.document
    .getElementById("txtResponse1").value = "yourValue"
    .getElementById("cmdRespond1").Click '.Submit
End With

你好,内塞特,谢谢你的密码。不幸的是,它不能与error msg unspecified error/automation error一起工作。在“Set objCollection=ie.Document.getElementsByTagName(“textarea”)”行出现错误,您可以尝试将其更改为
Set objCollection=ie.Document.getElementsByID(“txtResponse1”)
。我从来没有见过你所描述的错误,所以我不知道为什么会这样。当我今天晚些时候回家的时候,我将尝试用textarea制作一个html代码来测试。我们刚到家,用基本的html元素制作了一个快速测试站点,我得到了和你一样的错误。我发现,如果你在互联网和本地内联网上,情况会有所不同。当它位于本地Intranet上时,您必须将
设置ie=CreateObject(“InternetExplorer.Application”)
更改为
设置ie=New InternetExplorerMedia
,并添加引用“Microsoft Internet控件”(VBAEditor>工具>引用)哇!它起作用了。非常感谢你,尼塞特!非常感谢!我现在将根据你的意见开始我的项目。再次感谢您。非常欢迎您,在再次查看代码之后,我确信它可以进行一些优化。工作结束后,我们会努力让事情变得更好:)