Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 32 of 32

Thread: "Auto Complete" Internet Form

  1. #21
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    I got that same msgbox, I actually assumed you saw your name/pw in there too and changed your PW afterwards (since I tested with your data )

    Since I'm new to this, I can't say for sure, but perhaps it is because it is not a username we're entering here but an email address?

    I also tried using my XMLHTTP technique of logging in, same response.
    [vba] Dim MyRequest As Object 'New WinHttp.WinHttpRequest
    Set MyRequest = CreateObject("MSXML2.XMLHTTP")
    MyRequest.Open "GET", _
    "https://www.google.com/accounts/ServiceLoginAuth"

    'Set credentials

    Dim strParams As String
    MyRequest.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    strParams = "Email=email@gmail.com&Passwd=yourpassword"
    ' MyRequest.SetCredentials "email@gmail.com", "yourpassword", _
    HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
    ' Send Request.
    MyRequest.Send strParams[/vba]Not sure what else to say, hopefully Stan will be around to help steer us in the right direction

  2. #22
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Well Gmail doesn't require the email address...you can put a username then password....




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  3. #23
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    I said that based solely on the wording of the https://www.google.com/accounts/ServiceLoginAuth page.. no idea why it isn't working

  4. #24
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    221
    Location
    Quote Originally Posted by mvidas
    The source you have there is just of the main frame for the page, not the source for the whole page

    Looking at the line:
    <frame name="docent_main" src="?CMD=GET&file=catalog/plan_summary.jsm">

    What happens if you try getting that?
    If you're looking at www.domain.com/index.php, try getting www.domain.com/index.php?CMD=GET&file=catalog/plan_summary.jsm or maybe just www.domain.com/catalog/plan_summary.jsm

    If you're using the IE object you could always change frames as well, I believe it is a property of the document property, like:[vba]IE.Document.Frames(0).Body.Forms(0)...[/vba]Matt
    Ok perfect, you were right. I was able to get the correct frames source code, and I can muddle in there to figure it out, thank-you.

    In order to have it work, I need to be able to "tab" through-out frames, to select links, and buttons to navigate back to the same spot each time. Once I can do this Im set .... i hope .... any sugguestions ?

  5. #25
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    221
    Location
    [vba]Dim ie As New InternetExplorer[/vba]
    This opens up a new browser, is there a way I could ask it to use the existing browser ? This way, I do not need as much code to navigate to my form pages. Thanks again.

  6. #26
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    You could have it reuse an existing window, if one exists:[vba] Dim IE As Object
    On Error Resume Next
    Set IE = GetObject(, "internetexplorer.application")
    On Error GoTo 0
    If IE Is Nothing Then
    'no existing IE window
    Set IE = CreateObject("internetexplorer.application")
    IE.Navigate2 "about:blank"
    Do While IE.readyState <> 4
    DoEvents
    Loop
    Else
    'IE now refers to an existing browser window
    End If[/vba]Matt

  7. #27
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    221
    Location
    You have been great help, thanks matt.

  8. #28
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    221
    Location
    Ok, I am still ahving a little trouble. I am trying to use the existing browser window (this part is working) and copy from excel, to the textboxs on the existing window.

    Below i have a sample of the source code for the site, and the vba that I am currently using as a test. can anyone help ?

    SOURCE CODE :

    User 1:
    </TD>
    <TD colspan="2" NOWRAP>
    <INPUT TYPE="TEXT" NAME="User1" onchange="return setIsDirty('IsUserDirty1');" MAXLENGTH="15">
    <FONT COLOR="RED">*</FONT>
    <INPUT type="hidden" name="IsUserDirty1" value="0" >
    </TD>
    <TD colspan="2" NOWRAP>
    <INPUT TYPE="TEXT" size="30" NAME="LastName1" onchange="return setIsDirty('IsUserDirty1');" MAXLENGTH="50">
    <FONT COLOR="RED">*</FONT>
    </TD>
    <TD colspan="2" NOWRAP>
    <INPUT TYPE="TEXT" NAME="PhoneNumber1" onchange="return setIsDirty('IsUserDirty1');" MAXLENGTH="24">
    <FONT COLOR="RED">*</FONT>
    </TD>
    <TD colspan="2" NOWRAP>
    <INPUT TYPE="TEXT" NAME="Email1" onchange="return setIsDirty('IsUserDirty1');" MAXLENGTH="50">
    <FONT COLOR="RED">*</FONT>
    </TD>
    </TR>

    VBA I am trying to use :

    [vba]
    Option Explicit

    Sub IE_login()

    Dim IE As Object
    On Error Resume Next
    Set IE = GetObject(, "internetexplorer.application")
    On Error GoTo 0
    If IE Is Nothing Then

    'no existing IE window
    Set IE = CreateObject("internetexplorer.application")
    IE.Navigate2 "about:blank"
    Do While IE.ReadyState <> 4
    DoEvents
    Loop
    Else
    'IE now refers to an existing browser window
    End If
    '*---------------------------------------------------------------
    'Dim IE As InternetExplorer
    Dim C
    Dim ULogin As Boolean, ieForm
    Dim MyPass As String, MyLogin As String
    redo:
    'what I want it to do is ieform = yada yada
    'mylogin should be sheet.range.a2 etc.
    MyLogin = Sheets("Intro").Range("a28")
    MyPass = Sheets("Intro").Range("b28")
    If MyLogin = "" Or MyPass = "" Then GoTo redo
    'Set IE = New InternetExplorer
    IE.Visible = True
    'IE.Navigate http://thewebsite I am using/

    'Loop until ie page is fully loaded
    Do Until IE.ReadyState = READYSTATE_COMPLETE
    Loop

    'Look for password Form by finding test "Password"

    'HOW TO FIND FORM : search from , then find 'input' and following will be name, i.e "f"
    'for site http://www.google.com/advanced_search

    'On Error Resume Next
    For Each ieForm In IE.Document.forms
    If InStr(ieForm.innertext, "user1") <> 0 Then
    ULogin = True
    'enter details
    ieForm(0).Value = MyLogin
    ieForm(1).Value = MyPass
    ieForm(2).Value = MyPass

    'login
    ieForm.submit
    Exit For
    Else
    End If
    Next
    If ULogin = False Then MsgBox "Nope, sorry..."
    Set IE = Nothing
    End Sub

    Sub SetRefs()
    Dim ObRef
    On Error Resume Next
    ' Adds Internet Controls Ref

    ThisWorkbook.VBProject.References.AddFromGuid "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 1, 1
    End Sub
    [/vba]
    I am well aware my code is sloppy, but I cannot wrap my head around this one.

  9. #29
    VBAX Contributor
    Joined
    Oct 2004
    Posts
    159
    Location
    The code below works for me to login Gmail

    [VBA] Option Explicit
    Dim myIE As InternetExplorer
    Dim myIEdoc As HTMLDocument
    Dim theForm As HTMLFormElement

    Sub OpenWebpageAndLogin(URL As String, myPW As String, myID As String)
    Dim theItm As HTMLFormElement
    Dim i As Integer
    Dim flg As Boolean
    Set myIE = New InternetExplorer
    With myIE
    .Navigate URL
    .Visible = True
    Do While .Busy: DoEvents: Loop
    Do While .ReadyState <> 4: DoEvents: Loop
    End With
    Set myIEdoc = myIE.Document
    Set theForm = findFm(myIEdoc)
    With theForm
    For i = 0 To .Length - 1
    Select Case .Item(i).Type
    Case "password"
    .Item(i).Value = myPW
    flg = True
    Case "text"
    .Item(i).Value = myID
    Case Else
    End Select
    Next
    End With
    If flg Then
    theForm.submit
    Else
    myIE.Quit
    MsgBox ("Unexpected Error, I'm quitting.")
    End If
    Set myIE = Nothing
    End Sub

    Function findFm(theDoc As HTMLDocument) As HTMLFormElement
    Dim i As Integer, j As Integer
    Dim theItm As HTMLFormElement
    With theDoc.forms
    For i = 0 To .Length - 1
    Set theItm = .Item(i)
    With theItm
    For j = 0 To .Length - 1
    If .Item(j).Type = "password" Then
    Set findFm = theItm
    Exit Function
    End If
    Next
    End With
    Next
    End With
    End Function

    Sub test()
    OpenWebpageAndLogin "https://www.google.com/accounts/ServiceLoginAuth", "YourPassword", "YourUserName"
    End Sub

    [/VBA]

  10. #30
    VBAX Contributor
    Joined
    Oct 2004
    Posts
    159
    Location
    Some web site may have two more questions (total 4 questions) for login.


    [VBA] Option Explicit
    Dim myIE As InternetExplorer
    Dim myIEdoc As HTMLDocument
    Dim theForm As HTMLFormElement
    Sub OpenWebpageAndLogin(URL As String, myPW As String, myID As String, _
    Optional myAns As String, Optional selItem As Integer)
    Dim theItm As HTMLFormElement
    Dim i As Integer
    Dim Testing As Variant
    Dim flg As Boolean
    Set myIE = New InternetExplorer
    With myIE
    .Navigate URL
    .Visible = True
    Do While .Busy: DoEvents: Loop
    Do While .ReadyState <> 4: DoEvents: Loop
    End With
    Set myIEdoc = myIE.Document
    Set theForm = findFm(myIEdoc, "password")
    With theForm
    For i = 0 To .Length - 1
    Testing = .Item(i).Name
    Select Case .Item(i).Name
    Case "password"
    .Item(i).Value = myPW
    flg = True
    Case "username"
    .Item(i).Value = myID
    Case "answer"
    .Item(i).Value = myAns
    Case "questionid"
    .Item(i).Value = selItem 'the quation's number
    Case Else
    End Select
    Next
    End With
    If flg Then
    Set theForm = findFm(myIEdoc, "submit")
    Else
    myIE.Quit
    MsgBox ("Unexpected Error, I'm quitting.")
    End If
    Set myIE = Nothing
    End Sub

    Function findFm(theDoc As HTMLDocument, theType As String) As HTMLFormElement
    Dim i As Integer, j As Integer
    Dim theItm As HTMLFormElement
    With theDoc.forms
    For i = 0 To .Length - 1
    Set theItm = .Item(i)
    With theItm
    For j = 0 To .Length - 1
    If .Item(j).Type = theType Then
    Set findFm = theItm
    If theType = "submit" Then .Item(j).Click
    Exit Function
    End If
    Next
    End With
    Next
    End With
    End Function


    Sub test()
    OpenWebpageAndLogin URL:="http://www.officefans.net/cdb/logging.php?action=login", _
    myPW:="xxxxxxxx", myID:="Emily", myAns:="xxxx", selItem:=7
    End Sub
    [/VBA]

  11. #31
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    221
    Location
    Ahh! I think this confuses me even more. I will attmept with the code and see what happens. Any hints on the source code I provided; what part I to focus on ?

  12. #32
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    221
    Location

    Fresh start

    Ok, I managed to get logged in using everyone's help.

    I am now looking for something I think I am very close to getting, but oh so very stuck. I have been trying to get this for months.

    I need do a similar task, only using the existing browser window, not a new one.
    I need to create a online account for users (first name, last name, email etc.)

    I am attaching the source code, and my vba, and hoping someone can correct what I am doing wrong, I have tried many things to not avail.

    (P.S - if if helps, there is a side bar menu, and the source code I have posted, is the main page, maybe that is my problem? I am not selecting the main page somehow?)

    Pease Help! this is driving me nuts!!

Posting Permissions

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