Hello,
Thanks to the code from both of you, I've managed to solve my core issue!
Normally, I have to go to my website and search for the item, and that won't change. Once I've found it now, though, I can return to Excel, and run the code below. It will evaluate all open IE windows to see which has the main part of the product URL (http://www.bcliquorstores.com/en/products) and then pull all the data from the appropriate table to Excel. Ultimately I'm going to code this for Access, but I'm pretty excited that I got this far! The only issue I have is that I have to make sure I only have one IE window with a BCLiquorstore link, or I may get the wrong info.
Sub QueryLiquorTable()
'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 n As Integer
Dim objWeb As QueryTable
Dim CoreURL As String
'Set main URL to evaluate open IE windows
CoreURL = "http://www.bcliquorstores.com/en/products"
Set sws = New SHDocVw.ShellWindows
'Cycle through all open IE windows and assign the window whose URL
'matches that decided above to a variable
For n = 0 To sws.Count - 1
If Left(sws.Item(n).LocationURL, Len(CoreURL)) = CoreURL Then
Set ieDoc = sws.Item(n).Document
Exit For
End If
Next n
'Retrieve the web table from the IE window
If Not ieDoc Is Nothing Then
Set objWeb = ActiveSheet.QueryTables.Add( _
Connection:="URL;" & ieDoc.URL, Destination:=Range("A1"))
With objWeb
.WebSelectionType = xlSpecifiedTables
.WebTables = "2" ' Identify your HTML Table here
.Refresh BackgroundQuery:=False
.SaveData = True
End With
Else
MsgBox "Sorry, the specificied domain is not showing" & vbCrLf & _
"in any open internet explorer windows", vbOKOnly + vbCritical
End If
End Sub
Originally Posted by
vanduzee_t
IIm also trying to find a way to trackdown 3 particular cell on the table. I know I can use the HTML Elements (but I don't know how to use them) for a table.
Terry, I did you get your issue solved yet? I don't know anything about HTML elements, but is there a Find method that you can use, rather than looping through all the cells?
Cheers,