Thanks for the quick response,
Your suggestion did return the data, but I am still getting some problems in returning the data to the same location every time, seems to be off by one row or column. Any suggestions?
Main Topics
Browse All TopicsI am trying to automatically grab various stock data from Yahoo finance. I wrote a macro for each page I want to grab data from, for example:
http://finance.yahoo.com/q
The macros first clear out the target worksheet, including the query from a previous run of the macro and then designates that the data is to be returned to cell A1, and in fact it selects A1 before going onto creating the web query for the current iteration. At the end of this message is an example of the macro for the first sample page listed above
There are about 10 web pages I am trying to get data from, and their is a macro for each page, and I wrote one macro to run each of these 10 individual macros. (I am concerned that the ubber macro is going onto a new page before the previous query is completed and this may add some headaches and would like your imput on this)
Anyways, some tables are grabed and placed in their worksheets as designed every time. But in other worksheets, such as the pages listed above and in the macro example included, the performance is much more mixed. In some cases they work fine, but other times some combination of 1) the data is returned to the wrong location within the worksheet 2) the wrong table or Item from the page is returned 3) no data is returned 4) only part of the desired table is returned.
When I went into the edit query function, sometimes the correct tables are marked for importation, some times they are not. There does not seem a pattern. I dont understand why this is happening, I recored each of these macros and they worked fine before I save the macro, so it should be returning the same data, the same way each time, but this is not happening.
I searched the MS KB and they mentioned that Dynamically Scripted Tables may be interfering with the query, if this is the case is there a solution to this problem?
Would it be better to right a macro/query for each individual table I want to grab? Though there are problems with macros/queries associated with pages where I am only going after a single table on that particular page.
The key is to retrieve the right data reliably to the correct location, any help would be greatly apprecciated.
Example Macro-
Sub keystats()
'
' keystats Macro
' Macro recorded 10/18/2004 by Michael J. Palma
'
'
'Setup worksheet
Sheets("keystats").Select
Cells.Select
Selection.clear
Selection.QueryTable.Delet
' Range("A:A,B:B").Select
' Range("B1").Activate
' Selection.Delete Shift:=xlToLeft
' Range("A1").Select
' Selection.EntireColumn.Ins
' Selection.EntireColumn.Ins
Range("A1").Select
'
With ActiveSheet.QueryTables.Ad
"URL;http://finance.yahoo.
.Name = "ks?s=IT_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "26,31,34,37,40,43,46,53,5
.WebPreFormattedTextToColu
.WebConsecutiveDelimitersA
.WebSingleBlockTextImport = False
.WebDisableDateRecognition
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
mjpalma,
So, the table itself is in the same location but the contents of the table change in column H. There's not much we can do about that since it is Yahoo's content. Ideally, you would probably want to capture the info from the returned query into a table of your own by scanning the query results looking for specific markers (like header info: FINANCIAL HIGHLIGHTS, TRADING INFORMATION, etc.) and moving only the data you were interested in into your new table.
Jim
Jim,
How did you discover the table name instead of the table number?
+++++++
From above:
.WebTables = "26,31,34,37,40,43,46,53,5
to:
.WebTables = "yfncsumtab"
++++++
I'm doing a similar query,
With ActiveSheet.QueryTables.Ad
Destination:=Cells(ColDown
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebTables = "23"
.WebPreFormattedTextToColu
.WebConsecutiveDelimitersA
.WebSingleBlockTextImport = False
.WebDisableDateRecognition
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
and it's in a loop which loops about 200 times. In about 50 of those cases, it brings in a different table. If I do the loop just once on one of those cases (that returned the wrong table in the loop) it returns the correct data. It seems to get confused with the repetition! I was hoping changing to the table name would help.
Thanks,
Loy Miller
Business Accounts
Answer for Membership
by: jeveristPosted on 2004-11-02 at 08:28:03ID: 12474217
mjpalma,
6,59"
How are you determining which tables to include? Try changing:
.WebTables = "26,31,34,37,40,43,46,53,5
to:
.WebTables = "yfncsumtab"
for all of these queries. You'll still have some problems with row heights but the data should end up in the same place every time.
Jim