Consulting

Results 1 to 5 of 5

Thread: Solved: auto login

  1. #1
    VBAX Contributor
    Joined
    Dec 2004
    Posts
    122
    Location

    Solved: auto login

    I am trying to auto login to this sight http://www1.mscdirect.com/cgi/nnsrhm[vba]Sub


    IE_login()
    Dim ie As InternetExplorer
    Dim C
    Dim ULogin As Boolean, ieForm
    Dim MyPass As String, MyLogin As String
    redo:
    MyLogin = Application.InputBox("Please enter your VBAX login", "VBAX username", Default:="login", Type:=2)
    MyPass = Application.InputBox("Please enter your VBAX password", "VBAX Password", Default:="Password", Type:=2)
    If MyLogin = "" Or MyPass = "" Then GoTo redo
    Set ie = New InternetExplorer
    ie.Visible = True
    ie.Navigate "http://www1.mscdirect.com/cgi/nnsrhm"
    'Loop until ie page is fully loaded
    Do Until ie.ReadyState = READYSTATE_COMPLETE
    Loop
    'Look for password Form by finding test "Password"
    For Each ieForm In ie.Document.forms
    If InStr(ieForm.innertext, "Password") <> 0 Then
    ULogin = True
    'enter details
    ieForm(0),Value = MyLogin
    ieForm(1).Value = MyPass
    'login
    ieForm.submit
    Exit For
    Else
    End If
    Next
    If ULogin = False Then MsgBox "User is aleady logged in"
    Set ie = Nothing
    End Sub[/vba]

    I can't seem to get the text of the input boxes into the proper fields on the sight. I can't seem to get the text of the input boxes to populate any feilds in that sight. Can anybody help me auto login.

    Thank you

  2. #2
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Hello again,

    Looking at the source for that page, the login form is named "f"
    Using that, you can make it much easier:[vba]Sub IE_login()
    Dim ie As InternetExplorer, ieForm As Object
    Dim MyPass As String, MyLogin As String
    Do
    MyLogin = Application.InputBox("Please enter your VBAX login", _
    "VBAX username", Default:="login", type:=2)
    MyPass = Application.InputBox("Please enter your VBAX password", _
    "VBAX Password", Default:="Password", type:=2)
    Loop Until Len(MyLogin) > 0 And Len(MyPass) > 0
    Set ie = New InternetExplorer
    ie.Visible = True
    ie.Navigate "http://www1.mscdirect.com/cgi/nnsrhm"
    'Loop until ie page is fully loaded
    Do Until ie.readyState = READYSTATE_COMPLETE
    DoEvents
    Loop

    On Error Resume Next
    'I'm guessing the form wont be there if already logged in
    Set ieForm = ie.Document.Forms("f")
    On Error GoTo 0
    If ieForm Is Nothing Then
    MsgBox "User is aleady logged in"
    Else
    ieForm.Item("SIUSER").Value = MyLogin
    ieForm.Item("SIPASS").Value = MyPass
    ieForm.Submit
    End If
    Set ie = Nothing
    End Sub[/vba]Matt

  3. #3
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Also, if the "f" form will always be there, you can remove the ieForm variable using a With block. Additionally, you don't need the application.inputboxes there, you can use standard ones if you just want text anyways. Lastly, if you want to give this code to someone that doesnt have the InternetExplorer reference checked, you can use late binding to do the same thing:[vba]Sub IE_login()
    Dim IE As Object, MyPass As String, MyLogin As String
    Do
    MyLogin = InputBox("Please enter your username", "Enter username", "Username")
    MyPass = InputBox("Please enter your password", "Enter Password", "Password")

    Loop Until Len(MyLogin) > 0 And Len(MyPass) > 0
    Set IE = CreateObject("InternetExplorer.application")
    IE.Visible = True
    IE.Navigate "http://www1.mscdirect.com/cgi/nnsrhm"
    'Loop until ie page is fully loaded
    Do Until IE.readyState = 4 '4=READYSTATE_COMPLETE
    DoEvents
    Loop
    With IE.Document.Forms("f")
    .Item("SIUSER").Value = MyLogin
    .Item("SIPASS").Value = MyPass
    .Submit
    End With
    Set IE = Nothing
    End Sub[/vba]Matt

  4. #4
    VBAX Contributor
    Joined
    Dec 2004
    Posts
    122
    Location
    OH thank you so much, I just could not get my hands around it at all. thanks again, i will mark this as solved.

  5. #5
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Glad to help! Please don't hesitate to ask if you have any questions

Posting Permissions

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