Results 1 to 4 of 4
  1. #1
    Join Date
    May 2009

    Unanswered: Extracting URL from active webpage

    Is it possible to extract the URL from a website you have open in IE? Ideally, I need to use the URL to extact information and put it in a form. Haven't had much luck in getting the URL extracted, but it seems downhill from here once you know the URL.

  2. #2
    Join Date
    May 2009
    Although not listing a specific solution, the following should help you get what you need:
    vba_corner: Working with Internet Explorer Using VBA



  3. #3
    Join Date
    Dec 2004
    Madison, WI
    I use code like this to post/get URL info which may help in your search for getting the actual URL address...(ie. I already know the MyURLAddress). But google "Microsoft.XMLHTTP" to see if this is the route you need to take.

    Dim objXMLHTTP, xml
    Set xml = Nothing
    Set xml = CreateObject("Microsoft.XMLHTTP")
    xml.Open "POST", MyURLAddress, False
    xml.send Data
    xml.Open "GET", MyURLAddress, False
    xml.send Data

    Me.LblRBody.Caption = xml.readystate
    Me.LblRStatus.Caption = xml.Status
    Me.LblRStatusText.Caption = xml.statustext
    Me.LblResponse.Caption = xml.ResponseText
    (note: there's other response types and info you can get from the URL status)
    set xml = nothing

    No need to add a reference.
    Last edited by pkstormy; 06-20-09 at 12:20.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  4. #4
    Join Date
    May 2009
    From the link I previously posted:
    Alternatively, you can skip the referencing and use late binding, defining the pointer to the Internet Explorer instance as Object instead of SHDocVw.InternetExplorer in your VBA code. But then you'll miss out on a lot of goodies like intellisense, full access to the object model via the object browser, access to the application's built-in constants, and a popup listing all the supported constants upon typing...
    So, you don't have to add a reference, but you can for intellisense, which does make it easier to write the logic. The same is true for the XmlHttp class.

    I had a bit of time to kill and I was curious, so I came up with the following, which will get you what you need. Only took about five minutes to cook up, based mostly on logic in my previously posted link:
    Function GetCurrentIEUrl() As String
        Dim objShellWindows As New SHDocVw.ShellWindows
        Dim objIE As SHDocVw.InternetExplorer
        ' Ignore errors when accessing the document property
        On Error Resume Next
        ' Loop over all shell windows
        For Each objIE In objShellWindows
            ' If the document is of type HTMLDocument, it is an IE window
            If TypeName(objIE.Document) = "HTMLDocument" Then
                GetCurrentIEUrl = objIE.LocationURL
                Exit Function
            End If
    End Function
    This will return the first Url encountered in an Internet Explorer window. If there is only one IE window and tab, it should work fine. If you need to see the URL for more than one window/tab, you'll need to use an array/delimited string/etc.



Posting Permissions

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