5

Web ページを開き、データを配置する必要がある場所を見つけ、マクロで事前入力ボタンを押してから [OK] をクリックするマクロを作成しました。

ボタンのページ ソース コードは次のとおりです。

<input type="text" size="30" maxlength="40" name="name" id="name">
<input type="button" value="Prefill" onclick="prefill()">

私は一週間中答えを探していました.ループを実行して検索することで、これがどのように機能するかについての基本的な理解があると思います.

私のページでこのボタンを検索するループを誰かに見せてもらえますか?

前もって感謝します。

これまでにリクエストされたコード

Private Sub Populate_Click()
    Dim i As Long
    Dim IE As Object
    Dim objElement As Object
    Dim objCollection As Object

    Set IE = CreateObject("InternetExplorer.Application")

    IE.Visible = True
    IE.Navigate "website" 'make sure you've logged into the page

    Do
        DoEvents
    Loop Until IE.READYSTATE = 3

    Do
        DoEvents
    Loop Until IE.READYSTATE = 4
    ActiveSheet.EnableCalculation = False
    ActiveSheet.EnableCalculation = True
    Call IE.document.getelementbyid("name").SetAttribute("value", ActiveSheet.Range("b2").Value)
    Call IE.document.getelementbyid("aw_login").SetAttribute("value", ActiveSheet.Range("a2").Value)

    Set objCollection = IE.document.getElementsByTagName("input")
    i = 0
    While i < objCollection.Length
        If objCollection(i).Type = "button" And _
            objCollection(i).Name = "Prefill" Then
                Set objElement = objCollection(i)
        End If
        i = i + 1
    Wend
    objElement.Click
End Sub
4

1 に答える 1

4

あなたはかなり近いようです、これは私が似たようなことをするために使用したものです

    With ie.document

        Set elems = .getelementsbytagname("input")
        For Each e In elems
            If (e.getattribute("className") = "saveComment") Then
                e.Click
                Exit For
            End If
        Next e

    End With

おそらく、if ステートメントを変更する必要があるだけです。

また、コードが参照していることに気付きました.Name = "Prefill"が、html スニペットは参照しています.value = "Prefill"

于 2013-06-19T01:37:26.773 に答える