0

I found here a code that actually input login data and login to website. It works on that website (so references are turned on correctly) - Login to a website using VBA . I am trying to use that in a company but I get an error when I adjust the names.

Am I doing something wrong?

Error: Run-time error 438 Object doesnt support this property or method.

It appears at line "oLogin.Value = UserName"

Sub login()

Const Url$ = "site.company.org"

Dim UserName As String, Password As String, LoginData As Worksheet
Set LoginData = ThisWorkbook.Worksheets("Sheet1")
UserName = LoginData.Cells(1, "B").Value
Password = LoginData.Cells(2, "B").Value

Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")

With ie

    .navigate Url
    ieBusy ie
    .Visible = True

    Dim oLogin As Object, oPassword As Object
    Set oLogin = .document.getElementsByName("login")(0)
    Set oPassword = .document.getElementsByName("heslo")(0)

    oLogin.Value = UserName
    oPassword.Value = Password
    .document.forms(0).submit

End With
End Sub



Sub ieBusy(ie As Object)
Do While ie.Busy Or ie.readyState < 4
    DoEvents
Loop
End Sub

Here is HTML for my website

<form name="login" method="post" enctype="multipart/form-data" action="./index.php?page=main/login.php">
<input type="hidden" name="chyba" value=""> 
<input type="hidden" name="odeslano" value="1">
<input type="hidden" name="redir_url" value="http://zinfo.kamax.org/">

<table align="left" class="NORMAL left">
<tbody><tr>
 <td align="right">*Login:</td>
 <td align="left"><input class="polozka_formulare_req" type="text" name="login" size="20" maxlength="20" value="" autofocus="autofocus"></td>
</tr>  
<tr>
 <td align="right">*Password:</td>
 <td align="left"><input class="polozka_formulare_req" type="password" name="heslo" size="12" maxlength="12" value=""></td>
</tr> 
<tr>
 <td align="right"></td>
 <td align="center">
  <br>
  <input type="submit" name="submit" value="Log In" class="TLAC">
  <!--<button class="TLAC" type="button" onClick="window.open('//website.company.org/','_self');return false;">Back</button>-->
 </td>
</tr> 
</tbody></table>

<div class="login_warn">
        Important Note to all Users:
        <br><br>
        All Documents in this system are for company internal use only. 
        Forwarding of any document or even parts of it to external parties without prior approval by QM or RD is strictly prohibited.
        </div>
    
</form>
Cœur
  • 37,241
  • 25
  • 195
  • 267

2 Answers2

1

You could target the input boxes. As noted you would need to handle frames/iframes first if they are present.

ie.document.querySelector("input[name=login]").Value ="n"
ie.document.querySelector("input[type=password]").Value ="x"
QHarr
  • 83,427
  • 12
  • 54
  • 101
0

Instead of trying to use an oLogin generic object, try referencing the webform directly like this:

ie.Document.ALL.login.Value = UserName

ie.Document.ALL.heslo.Value = Password

ArcherBird
  • 2,019
  • 10
  • 35