在vba中的“--- []”表达式中使用counter

时间:2015-09-15 07:54:41

标签: vba webforms

我有一个宏,可以在Web表单中从Excel输入数据。它看起来像这样: IE.document.all("substance[1][1]").Value = Cells(i, 6).Value

对于我添加的每一行,[]中的表达式都会发生变化。有没有办法实现自动化?就像是: IE.document.all("substance[n][m]").Value = Cells(i, 6).Value 所以我可以在循环结束时写n=n+1? 干杯

这是完整的代码:

Sub BOMcheckAutoEingabe()
Dim IE As Object
Dim Login As String
Dim Passwort As String
Dim row As Integer
row = 22
Set IE = CreateObject("InternetExplorer.Application")
With IE
    .Visible = True
    ShowWindow IE.hwnd, SW_MAXIMIZE
    .Navigate "https://demo.bomcheck.net/de/"
    Do Until .ReadyState = 4
    DoEvents
    Loop
    IE.document.all("username").Value = "****"
    IE.document.all("password").Value = "****"
    IE.document.all("Submit").Click
    Application.Wait Now + TimeValue("00:00:03")
    .Navigate "https://demo.bomcheck.net/de/parts/addfullmaterialsdeclaration" _
    & "#fmd-table"
    Application.Wait Now + TimeValue("00:00:05")
    SendKeys "{TAB 6}", True
    Application.Wait Now + TimeValue("00:00:02")
    If Sheets("FMD).Cells(row, 1) <> 0 Then
        IE.document.all("usage[1]").Value = Cells(row, 1).Value
    Else
    End If
End With
End Sub

2 个答案:

答案 0 :(得分:0)

已经在OP的评论中发布,这里是建议解决方案的测试

Sub test()
Dim n As Long, m As Long, Check As String
m = 1
For n = 1 To 10
    Check = "substance[" & n & "][" & m & "]"
    Debug.Print Check
Next n
End Sub

给你这个

enter image description here

只需在代码中遵循此逻辑

答案 1 :(得分:0)

转换为String解决了问题:

这个可以解决问题:

IE.document.all("usage[" + CStr(t) + "]").Value = Cells(zeile, 1).Value