Consulting

Results 1 to 7 of 7

Thread: How to login with vba

  1. #1

    How to login with vba

    Dear all,

    I am able to open a webpage - with vba but unable to login.

    Sub LoadThisWebPage()
    Dim oIE As SHDocVw.InternetExplorer
    
    'Set oIE = CreateObject("InternetExplorer.Application")
    Set oIE = New SHDocVw.InternetExplorer
    
    'Make the Inter*net Explorer visible
    oIE.Visible = True
    
    oIE.Navigate2   the reqd url
    
    '================
    'Wait till the browser is busy and page is fully loaded
    Do While oIE.Busy
    
    Loop
    
    Do While oIE.ReadyState < 4
    
    Loop
    '=================
    
    Dim hPage As HTMLDocument          'Object                         'HTMLDocument
    'Dim nameEdit As HTMLDocument
    Dim passWd As Object
    Dim Elements As IHTMLElementCollection
    Dim El As IHTMLElement
    
    Set hPage = oIE.Document
    
    'PROBLEM HERE ONWARDS
    
    'Set El = hPage.getElementById("Form1")
    
    'there is only one form
    With oIE.Document.forms(0).Elements(0)
      If .Name = "__VIEWSTATE" Then
        .Value = "999999"
         End If
    End With
    
    End Sub
    Please help

    Thanks in advance

    Regards,

    Geetha

  2. #2
    Actually i am able to get the HTML code with


    Dim oIE As SHDocVw.InternetExplorer
    
    Set oIE = New SHDocVw.InternetExplorer
    .
    .
    .
    .
    .
    Set hPage = oIE.Document
    Sheets("Sheet3").Cells(2, 5) = hPage.documentElement.innerHTML
    But unable to identify the elements to which i can put the reqd values for logging in

    Regards

  3. #3
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    613
    Location
    See if this works:

    Option Explicit
    Sub dataFromLeumi()
        Dim myPassword As String
        myPassword = "somepassword"
        Dim myUserName As String
        myUserName = "someusername"
    
    
    
    
    
    
        Dim loginPath As String
        loginPath = "https://somewebsite/Login.html"
        Dim IE As Object
        Set IE = CreateObject("InternetExplorer.application")
        IE.Visible = True
        IE.navigate loginPath
    
    
        Dim userName As Object
        Set userName = IE.document.getattribute("uid")
        userName.Item(0).Value = myUserName
    
    
        Dim password As Object
        password = IE.document.getelementbyid("password")
        password.Item(0).Value = myPassword
    
    
    
    
        IE.document.getelementbyid("enter").Click
    End Sub

  4. #4
    Yes Logit. this is what i am trying to do.

    Will try your codes and be back with how it worked out

    Thanks

  5. #5
    No Logit, it is not working

    i am getting stuch at the following line:
    Set userName = IE.Document.getAttribute("txtCRNNo") ' stuck here
    i changed the line to
    IE.Document.all.Item("txtCRNNo").Value = myUserName 'not working
    i changed your code a bit:
    i tried declaring IE As SHDocVw.InternetExplorer

    But there is no progress

    Regards,
    Geetha

  6. #6
    Hi all,
    tried so many ways but no success
    posting my code so soeone can point out the mistake

    Sub LoginToThisWebPage()
    Dim ie As SHDocVw.InternetExplorer
    
    
    'Set oIE = CreateObject("InternetExplorer.Application")
    Set ie = New SHDocVw.InternetExplorer
    
    
    'Make the Inter*net Explorer visible
    ie.Visible = True
    
    
    'Nav*i*gate to the www.gmail.com
    'oIE.Navigate2 "www.gmail.com"
    ie.Navigate2 "crn.religare.in/newcrn/CRN_Login.aspx"
    
    
    '================
    'Wait till the browser is busy and page is fully loaded
    Do While ie.Busy
    Loop
    
    
    Do While ie.ReadyState < 4
    Loop
    '================
    
    
    Dim hPage As HTMLDocument          'Object                         'HTMLDocument
    Dim oUserID As Object
    Dim oPassWd As Object
    Dim ElCol As IHTMLElementCollection
    Dim El As IHTMLElement
    
    
    Set hPage = ie.Document
    'Sheets("Sheet3").Cells(2, 5) = hPage.documentElement.innerHTML
    
    
    Set El = hPage.forms("Form1")
        With El
            'Debug.Print "  .elements(" & e & ")"
            'Debug.Print "    .tagName=" & .tagName & " ---  .Name=" & .Name & " ---  .ID=" & .ID & " ---   .Value=" & .Value
            '.all.Item("_EVENTTARGET").Value = "***x"
        
        End With
    
    
    End Sub

  7. #7
    i am using excel 2000
    can this also be a reason for my not being able to do this programming?

    Regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •