Web Query question | Receiving data from a password protected webpage

Plastikman

New Member
Joined
Apr 25, 2011
Messages
9
Dear Excel experts!

I would like to automatically collect data from a password protected webpage but I can not find a proper way to do it. I manage to log in on the main page but then I can't collect chosen data. Any ideas?

My code so-far...

Code:
Sub X11LogIn_Open()

[COLOR=#008000]'I didn't wrote "the login code". It is something I found earlier in a excel forum. Slightly re-coded though
[/COLOR]
Dim IE As Object

    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = False
    IE.Navigate "http://www.xperteleven.com/" [COLOR=#008000]'login (main)page[/COLOR]

[COLOR=#008000]'Check for good connection to web page loop![/COLOR]

Do
    If IE.ReadyState = 4 Then
    IE.Visible = False
Exit Do
    Else
        DoEvents
    End If
Loop
    Application.Wait (Now + TimeValue("0:00:05"))

[COLOR=#008000]'Wait for window to open![/COLOR]

    IE.Visible = True

[COLOR=#008000]'Send log-on information![/COLOR]

    SendKeys "{TAB}", True
    SendKeys "{TAB}", True
    SendKeys "{TAB}", True
    SendKeys "{TAB}", True
    SendKeys "{TAB}", True
    SendKeys "{TAB}", True
    SendKeys "{TAB}", True
    SendKeys "{TAB}", True
    SendKeys "{TAB}", True
    SendKeys "{TAB}", True
    SendKeys "USERNAME", True
    SendKeys "{TAB}", True
    SendKeys "{TAB}", True
    SendKeys "PASSWORD", True
    SendKeys "{ENTER}", True

[COLOR=#008000]'Log in code ends here...[/COLOR]
[COLOR=#008000]
'...and web Query starts[/COLOR]

    Application.Wait (Now + TimeValue("0:00:05"))
    IE.Navigate "http://www.xperteleven.com/team.aspx?TeamID=1102399&dh=5" [COLOR=#008000]'<-- It is from this page I would like to recieve data![/COLOR]
    Application.Wait (Now + TimeValue("0:00:05"))

    Sheets("Query").Select
    
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://www.xperteleven.com/team.aspx?TeamID=1102399&dh=5", Destination:= _
        Range("$A$1"))
        .Name = "team.aspx?TeamID=1102399&dh=5_1"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlSpecifiedTables
        .WebFormatting = xlWebFormattingNone
        .WebTables = "11"
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
End Sub

Many thanks :)
 

Some videos you may like

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,624
I don't think you can combine IE automation and a web query; at least I've never seen it done. You'll have to use IE automation and HTMLDocument parsing to import the web data by looking at the HTML source. Searching the forum should find many VBA examples. Also, the log in can be done using IE automation rather than with SendKeys which is unreliable.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,381
Messages
5,601,302
Members
414,440
Latest member
Kim0204

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top