Excel VBA脚本使用IE预填网上表格? [英] Excel VBA script to prefill online form using IE?

查看:437
本文介绍了Excel VBA脚本使用IE预填网上表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助。我正在尝试编写一个VBA脚本,它将使用列A中的值,并将其放在没有ID但名称(OldUrl)的输入元素的在线表单中。然后,VBA脚本将在列B中的相邻单元格中获取值,并将其放在名为(NewUrl)的输入字段中以相同的形式(digiSHOP)。



该表单位于一个安全的服务器上,但我已经得到了窗口拉起并选择了窗体。我无法找到一种方法来定位输入字段,因为它们没有ID。以下是我的代码,感谢您的帮助。

  Sub Redirect()
Dim IE As Object
Dim doc As Object
Dim form As Object
Dim OldURL As Object
Dim NewURL As Object

设置IE = CreateObject(InternetExplorer.Application)

与IE
.Visible = True
.Navigatehttps:// ....

Do Until .ReadyState = 4:DoEvents:Loop

设置doc = IE.Document
设置form = doc.forms(digiSHOP)
设置OldURL = doc.getElementById(OldUrl)'元素没有ID
OldURL.Value = Range(A2)
设置NewURL = doc.getElementById(NewUrl)
NewURL.Value = Range(B2)
form.submit

Do Until .ReadyState = 4:DoEvents:Loop
Do While .Busy:DoEvents:Loop

End with
End Sub

此外,我不知道如何定位整个列并循环,因此值设置为单元格A2。这更是测试脚本。

解决方案

  Sub Redirect()
Dim IE As Object
Dim doc As Object

设置IE = CreateObject(InternetExplorer.Application)

使用IE
.Visible = True
.Navigatehttps: // ....

Do Until .ReadyState = 4:DoEvents:Loop

With .Document.forms(digiSHOP)
.elements( OldUrl)Value = Range(A2)
.elements(NewUrl)。Value = Range(B2)
.submit
End with

Do Until .ReadyState = 4:DoEvents:Loop
Do While .Busy:DoEvents:Loop

End with
End Sub


I am in need of assistance. I am trying to write a VBA script that would take the value in column A and place it on an online form in an input element with no ID but the name ("OldUrl"). Then the VBA script would take the value in the adjacent cell in column B and place that in the same form ("digiSHOP") in the input field named ("NewUrl").

The form is on a secure server however I have gotten as far as the window pulling up and the form selected. I am having trouble finding a way to target the input field since they have no ID. Below is my code and thank you for your help.

Sub Redirect()
Dim IE As Object
Dim doc As Object
Dim form As Object
Dim OldURL As Object
Dim NewURL As Object

Set IE = CreateObject("InternetExplorer.Application")

With IE
    .Visible = True
    .Navigate "https://...."

    Do Until .ReadyState = 4: DoEvents: Loop

    Set doc = IE.Document
    Set form = doc.forms("digiSHOP")
    Set OldURL = doc.getElementById("OldUrl")'Error occurs here. Element has no ID
    OldURL.Value = Range("A2")
    Set NewURL = doc.getElementById("NewUrl")
    NewURL.Value = Range("B2")
    form.submit

    Do Until .ReadyState = 4: DoEvents: Loop
    Do While .Busy: DoEvents: Loop

    End With
End Sub

Also I wasn't sure how to target the entire column and loop it therefore the Value is set to the cell A2. This was more to test the script.

解决方案

Sub Redirect()
Dim IE As Object
Dim doc As Object

    Set IE = CreateObject("InternetExplorer.Application")

    With IE
        .Visible = True
        .Navigate "https://...."

        Do Until .ReadyState = 4: DoEvents: Loop

        With .Document.forms("digiSHOP")
            .elements("OldUrl").Value = Range("A2")
            .elements("NewUrl").Value = Range("B2")
            .submit
        End With

        Do Until .ReadyState = 4: DoEvents: Loop
        Do While .Busy: DoEvents: Loop

    End With
End Sub

这篇关于Excel VBA脚本使用IE预填网上表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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