完整的在线表格VBA

问题描述 投票:1回答:1

我创建了一个测试表单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'

我试图通过这个代码错误,谢谢你的时间!

html excel vba web
1个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.