简体   繁体   中英

VBA not filling in by element ID

I have got some trubles with my code. It works fine on Sharepoint site - its dummy site for me to practice and get things done; but on working site its not working. Problem is, I have e-mail, got all elements from it and trying to auto fill in on site, but nothing happens Parsing is going like this:

Dim ie As InternetExplorerMedium

Set ie = New InternetExplorerMedium

ie.Visible = True
ie.Navigate2 MarrPlazaWebForm

Do
    DoEvents
Loop Until ie.Busy <> True Or ie.readyState = READYSTATE_COMPLETE

With ie
    .document.getElementById("label-for-pass_date_to").value = dateFrom
    .document.getElementById("label-for-pass_date_from").value = dateTo
    .document.getElementById("label-for-pass_username").value = guestName
    .document.getElementById("label-for-pass_description").value = requestorName
    .document.getElementById("pass_full_day").Checked = True

    Set elems = .document.getElementsByClassName("btn btn-primary")
    For Each e In elems
        If (e.getAttribute("type") = "submit") Then
            e.Click
            Exit For
        End If
    Next e
End With

On Error Resume Next
ie.Quit

The site does not get elements by id and just leaves them empty

The site code with elements looks like this:

<input type="text" id="label-for-pass_date_to" name="pass_date_from" class="form-control js-datepicker-from hasDatepicker" autocomplete="off" placeholder="From" data-datepicker-disabled-date-before="true" data-mask="date">
<input type="text" id="label-for-pass_date_from" name="pass_date_to" class="form-control js-datepicker-to hasDatepicker" autocomplete="off" placeholder="Untill" data-datepicker-disabled-date-before="true" data-mask="date">
<input type="text" id="label-for-pass_username" name="pass_username[0]" class="form-control" placeholder="Name of guest">

and so on...

I have suspicion, that maybe the working site is composed in JavaScript and all Id's are not what im looking for Any suggestions?

I finally found out the problem

Dim ie As InternetExplorerMedium - I used "InternetExplorer", and it started to work as it should be.

Thanks for your suggestions and responses - hope it will come in handy I still don't get it, why it worked out like this - maybe due some security polices in my company

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM