Consulting

Results 1 to 4 of 4

Thread: Difference between .responsetext and .document

  1. #1
    VBAX Newbie
    Joined
    May 2012
    Posts
    4
    Location

    Difference between .responsetext and .document

    I'm trying to understand the difference between .responsetext and .document. Can someone provide an explanation?

    Here are two pieces of code. The first fails and the second is successful, but I do not understand why. I feel like both should return the contents of a website, but they do not. It's strange because I have other methods that successfully use IE.document.all("text").Value to return specific information from part of a website. I guess it can't return all of the website content?

    First code:
    Dim IE As New InternetExplorer
    IE.Visible = True
    IE.navigate "website"

    Do
    DoEvents
    Loop Until IE.readyState = READYSTATE_COMPLETE

    Dim xmlHttp As Object
    Dim Doc As String


    xmlHttp = IE.document.Value
    Doc = xmlHttp.responseText


    Second code:
    strURL = "website"
    Set xmlHttp = CreateObject("msxml2.xmlhttp")
    With xmlHttp
    .Open "get", strURL, False
    .send
    pageText = .responseText
    End With

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Document is an object. Remove .Value. Of course msdn documents what responsetext means. http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

  3. #3
    VBAX Newbie
    Joined
    May 2012
    Posts
    4
    Location
    Thanks for the reply Kenneth. In that case, I would assume the following returns a string, but it fails. What am I doing wrong? How should I modify the statement below?

    Doc = IE.document.responseText

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    I don't see responseText a member of the Document object. Intellisense will show you if it is. You are probably better off using each as needed.

    For an example of early binding for WinHttpRequest object see: http://vbaexpress.com/forum/showthread.php?t=25616

    Here is an example using the internetexplorer object for my login to Yahoo. I only include it here to show the references.

    [VBA]Sub Test_LoginYahoo()
    LoginYahoo ThisWorkbook.Worksheets("Main").Range("A1").Value2, _
    ThisWorkbook.Worksheets("Main").Range("A2").Value2
    End Sub

    ' Add references in Tools > References for:
    ' Microsoft HTML Object Library
    ' Microsoft Forms 2.0 Object Library
    ' Microsoft Internet Controls
    Sub LoginYahoo(username As String, password As String)
    Const strURL_c As String = "http://mail.yahoo.com"
    Dim objIE As SHDocVw.InternetExplorer
    Dim ieDoc As MSHTML.HTMLDocument
    Dim tbxPwdFld As MSHTML.HTMLInputElement
    Dim tbxUsrFld As MSHTML.HTMLInputElement
    Dim btnSubmit As MSHTML.HTMLInputElement

    Excel.Application.Cursor = xlWait
    If InStr(username, "@") = 0 Then username = username & "@yahoo.com"

    On Error GoTo Err_Hnd

    'Create Internet Explorer Object
    Set objIE = New SHDocVw.InternetExplorer
    'Navigate the URL
    objIE.Navigate strURL_c
    objIE.Visible = False
    'Wait for page to load
    Do Until objIE.ReadyState = READYSTATE_COMPLETE: Loop
    'Do While objIE.Busy Or objIE.ReadyState <> READYSTATE_COMPLETE
    ' DoEvents
    'Loop
    'Set document object
    Set ieDoc = objIE.document
    ieDoc.getElementsByName("passwd").Item(0).Value = password
    ieDoc.getElementsByName("username").Item(0).Value = username
    ieDoc.forms("Login_form").Submit

    Err_Hnd: '(Fail gracefully)
    objIE.Visible = True
    On Error GoTo 0
    Excel.Application.Cursor = xlDefault
    End Sub
    [/VBA]

Posting Permissions

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