Filling Internet Explorer inputbox

前端 未结 3 1483
你的背包
你的背包 2021-01-19 01:38

I read so many answers to my problem but somehow if I try to \"mimic\" what I see, I still am not able to do what I need.

The problem is very simple: fill an inputbo

相关标签:
3条回答
  • 2021-01-19 01:51

    You can try cycling all input and selecting the one is named as you need:

    Set Elements = IE.document.getelementsbytagname("Input")
    For Each Element In Elements
        If Element.Name = "Nachnamevalue" Then
            Element.Value = {Here your value}
            Exit For
        End If
    Next Element
    
    0 讨论(0)
  • 2021-01-19 01:52

    GetElementById gets an element by its id attribute, but "Nachnamevalue" is the value of the name attribute.

    To use the name:

    .document.Forms("Suchform").Elements("Nachnamevalue").value = "xxx"
    
    0 讨论(0)
  • 2021-01-19 02:15

    This worked for me. The code uses HTML from your question in file c:\Temp\page1.html.

    Option Explicit
    
    ' Add reference to Microsoft Internet Controls
    ' Add reference to Microsoft HTML Object Library
    
    Sub AddInfoFromIntranet()
    
        Dim ie As SHDocVw.InternetExplorer
        Dim doc As MSHTML.HTMLDocument
        Dim elements As MSHTML.IHTMLElementCollection
        Dim nachnameValueInput As MSHTML.HTMLInputElement
    
        Set ie = New SHDocVw.InternetExplorer
    
        With ie
            .Visible = True
            .navigate "c:\Temp\page1.html"
            Do Until Not .Busy And .readyState = 4
                DoEvents
            Loop
    
            Set doc = .document
            Set elements = doc.getElementsByName("Nachnamevalue")
    
            If Not elements Is Nothing Then
                Set nachnameValueInput = elements(0)
                If Not nachnameValueInput Is Nothing Then _
                    nachnameValueInput.Value = "{here goes whar I want to insert}"
            End If
    
            .Quit
        End With
    
        Set ie = Nothing
    
    End Sub
    

    To check the names of all input elements which exist at the momonet you execute the VBA code on the page you could use getElementsByTagName("input").

        Set elements = doc.getElementsByTagName("input")
    
        If Not elements Is Nothing Then
            Dim inputElement
            For Each inputElement In elements
                Debug.Print inputElement.Name
            Next inputElement
        End If
    
    0 讨论(0)
提交回复
热议问题