完整的在线表格VBA

时间:2019-04-24 13:11:11

标签: html excel vba web

我已经创建了一个测试表单here,并尝试使用excel文件中的值填写该表单。

我的代码在以下行停止:'调用ie.Document.getelementbyid(“ input_11”)。setAttribute(“ value”,activity)',并且它不会从第一个单元格复制数据,这就是我的excel文件的方式看起来像:

enter image description here

'Sub internet()

Dim ie As Object
Dim activitate As String
Dim LastRow As Long
Dim i, j As Integer
i = 1
LastRow = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row - 1
j = 0

'open page
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate "https://form.jotformeu.com/91133129129351"
Do
DoEvents
Loop Until ie.ReadyState = 4

While i < 11
For Each c In Range("2:2")
activity = c.Value
Call ie.Document.getelementbyid("input_11").setAttribute("value", activity)
Next c
Wend


End Sub'

我正试图克服此代码错误,谢谢您的宝贵时间!

1 个答案:

答案 0 :(得分:1)

我认为一定是这样的

Sub test()

    Dim IeApp As Object
    Dim IeDoc As Object
    Dim ieEL As Object

    Set IeApp = CreateObject("InternetExplorer.Application")
        IeApp.Visible = True ' make Explorer visible
            IeApp.Navigate "https://form.jotformeu.com/91133129129351"
        Do While IeApp.Busy: DoEvents: Loop ' wait for page load
        'Do Until IeApp.readyState = READYSTATE_COMPLETE: DoEvents: Loop

        Set IeDoc = IeApp.Document ' set loaded content to variable
            For Each ieEL In IeDoc.getElementsByTagName("input") ' loop all inputs
                If InStr(ieEL.Name, "activitate") > 0 Then ' check if inputs name has activate name
                    i = i + 1 ' increment for pick up valaues from sheet
                    ieEL.Value = ThisWorkbook.ActiveSheet.Cells(2, i).Value ' set value from sheets 2 row and i column
                End If
            Next
End Sub