我的公司需要重置超過1000人的用戶名和密碼,而不是通過手工完成,我希望VBA能夠爲我自動執行它。我有它連接到IE窗口罰款,但getElementsByTagName(「輸入」)只返回最後一個輸入標記。以下是我的代碼:Excel VBA getElementsByTagName()只返回最後一個輸入
Dim shellWins As ShellWindows
Dim IE As InternetExplorer
Dim HTMLdoc As HTMLDocument
Dim objElement As Object
Dim objCollection As IHTMLElementCollection
Dim name As String
Dim val As String, val2 As String
Dim a
Set shellWins = New ShellWindows
If shellWins.Count > 0 Then
' Get IE
Set IE = shellWins.Item(0)
Else
' Create IE
Set IE = New InternetExplorer
IE.Visible = True
End If
Set objCollection = IE.Document.getElementsByTagName("input")
For i = 0 To objCollection.Length
name = objCollection(, i).name
If Left(name, 6) = username Then
val = objCollection(i).Value
a = Split(val, "@")
If Left(a(1), 1) <> "s" Then
val2 = a(0) & sa & a(1)
Else
val2 = val
End If
objCollection(i).Value = val2
ElseIf Left(name, 6) = pswd Then
objCollection(i).Value = nPswd
End If
Next
Set shellWins = Nothing
Set IE = Nothing
我想要的輸入標籤是在表標籤中,是否會導致它?如果是這樣,我將如何引用表中的標籤?
預先感謝您。
你忽略了一些代碼嗎? –