Hi Guys,
I'm having a bit of an issue with something. I want to get the content from an IE window (a table) into an Excel worksheet. In the past, I've used the QueryTable method, (code below,) but they've recently upgraded it and it doesn't work any more.
The website takes a login and password, which I have, but I suspect that it is this that is giving the issue. The querytable method works by setting up a querytable to the URL, but if you paste the URL in a web browser, it comes back to the login page. At least... it does if you close IE.
Honestly, I don't really want to send a new request anyway. I want the results directly off the exisiting page. Does anyone have a way?
Here's the querytable code (which if memory serves, Tony Jollans helped me with ages ago.):
[vba]Function RetrieveQueryTable() As Boolean
'Requires reference to Microsoft Internet Controls
'Should work with any web table, provided it is not in a frame!
'Can change the coreURL to be assigned from a worksheet
Dim sws As SHDocVw.ShellWindows
Dim ieDoc As Object
Dim objWeb As QueryTable
'Incoporate error handling
On Error GoTo ExitRoutine
'Establish link to IE application
Set sws = New SHDocVw.ShellWindows
'Assign URL in IE window to a string
Set ieDoc = sws.Item(0).Document
'Retrieve the web table from the IE window
If Not ieDoc Is Nothing Then
'Clear the sheet and create the target range
With Worksheets("QueryTarget")
.Cells.Clear
Set objWeb = .QueryTables.Add( _
Connection:="URL;" & ieDoc.URL, _
Destination:=.Range("A1"))
End With
With objWeb
.WebSelectionType = xlSpecifiedTables
.WebTables = "6" ' Identify your HTML Table here
.Refresh BackgroundQuery:=False
.SaveData = True
End With
Else
MsgBox "Sorry, I can't find an Internet Explorer document", vbOKOnly + vbCritical
End If
ExitRoutine:
If Err.Number <> 0 Then
RetrieveQueryTable = False
Else
RetrieveQueryTable = True
End If
On Error GoTo 0
Set objWeb = Nothing
Set ieDoc = Nothing
Set sws = Nothing
End Function[/vba]