使用vba将文本输入到html输入框中 [英] Input text into html input box using vba

查看:611
本文介绍了使用vba将文本输入到html输入框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用VBA在Internet Explorer页面上输入一个值。我看过类似的帖子,但似乎无法查明我的问题。我对VBA有点流利,但HTML对我来说是新的。每当您加载页面时,我访问的网页上的ID属性都会发生变化。这是我试图访问的HTML元素的一个镜头:

 < input type =textsize =20 style =text-align:right; width:261px; autocomplete =offid =ext-comp-1067name =user_numbers.1.number_1class =x-form-text x-form-field x-form-num-fieldtitle => 

我现在使用的代码在这里:

  Sub OpenWebPage()

Dim ObjCollection As Object
Dim i As Long
Dim objElement As Object
Dim doc as Object
Dim form As Object



Dim ie As Object
Set ie = CreateObject(INTERNETEXPLORER.APPLICATION)
ie .Navigatehttp://11.182.123.21/#!/view/dashboards/dashboard-1
ie.Visible = True
虽然ie.Busy
DoEvents
Wend


Application.Wait Now + TimeValue(00:00:10)

设置ObjCollection = ie.Document.getElementsByName(user_numbers.1.number_1 ).Value =123

End sub

名称user_number .1.number_1我认为是我可以用来查找这个输入框的html中唯一的元素,每当你打开网页时ID都会改变。
如何在此字段中输入值?



谢谢!

解决方案

正如sid提到的,你有一个额外的=符号。
$ b 替换

  Set ObjCollection = ie.Document.getElementsByName( 


$ b $ p









$ b

  ie.Document.getElementsByName(user_numbers.1.number_1)(0).Value =123

这只是我的头脑,没有经过测试的代码。如果这不起作用,可用(1)替换上面代码中的(0)。 b
$ b

如果页面上没有其他元素具有相同的名称,那么这将起作用。
否则在上述语句中用适当的序号替换(0)


I am trying to input a value into a from on an internet explorer page using VBA. I have seen similar posts but can't seem to pinpoint my problem. I am somewhat fluent with VBA but HTML is new to me. The ID attributes change on the webpage I am accessing every time you load the page. Here is a shot of the HTML element I am trying to access:

<input type="text" size="20" style="text-align: right; width: 261px;" autocomplete="off"    id="ext-comp-1067" name="user_numbers.1.number_1" class="x-form-text x-form-field x-form- num-field" title="">

The code I am currently using is here:

    Sub OpenWebPage()

    Dim ObjCollection As Object
   Dim i As Long
Dim objElement As Object
Dim doc As Object
Dim form As Object



    Dim ie As Object
    Set ie = CreateObject("INTERNETEXPLORER.APPLICATION")
    ie.Navigate "http://11.182.123.21/#!/view/dashboards/dashboard-1"
    ie.Visible = True
    While ie.Busy
        DoEvents
   Wend


    Application.Wait Now + TimeValue("00:00:10")

 Set ObjCollection = ie.Document.getElementsByName("user_numbers.1.number_1").Value = "123"

End sub

The name "user_number.1.number_1" I think is the only element in the html that I can use to find this input box, the ID changes every time you open the webpage. How do I got about entering a value in this field?

Thank you!

解决方案

As sid mentioned, you have an extra "=" sign.

Replace

Set ObjCollection = ie.Document.getElementsByName("user_numbers.1.number_1").Value = "123"

with

ie.Document.getElementsByName("user_numbers.1.number_1")(0).Value = "123"

This is just off my head and not tested code. If this doesn't work replace (0) in the above code with (1).

If there is no other element on the page with the same name then this will work. Otherwise replace (0) in the above statement with appropriate ordinal position.

这篇关于使用vba将文本输入到html输入框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆