View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Herbert Herbert is offline
external usenet poster
 
Posts: 23
Default Dynamic Web Query from VBA

Hi Mike,
this is a primitive code snippet that might help you on the way.
The assumption here is that a webquery already exists on your sheet.
Note that not all of the page is imported. You can figure out the selected
tables by recording the creation of your webquery with the macro recorder ...

Sub ChangeURL(sParam as String)

Dim qt As QueryTable

If ActiveSheet.QueryTables.Count 0 Then
Set qt = ActiveSheet.QueryTables(1)

With qt
.Connection = "URL;http://finance.yahoo.com/q?s=" & sParam
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebSelectionType = xlSpecifiedTables
' only certain tables are imported ...
.WebTables = "19,23,25"
.Refresh
End With

End If

End Sub

"ThisShouldBeEasy" wrote:

Hi,

I'm trying to pull down information from a web site. I need to do it
multiple times with one of the parameters in the url changing each time. I
know it's possible but I can't seem to find the proper way to do this.

example:
http://finance.yahoo.com/q?s=aa

the s=aa would need to change to something like s=ge and then something like
s=pfe, etc.

Any help greatly appreciated.

Mike