Excel Web Query

G

Guest

Hi

I am trying to write a web query in vba using the following code

--------------------------------------

sheets("Sheet1").selec

varconnection = "http://www.yahoo.com

With ActiveSheet.QueryTables.Add(Connection:=
"URL;" & varconnection, Destination:=Range(
"A1")
.FieldNames = Fals
.RefreshStyle = xlInsertDeleteCell
.RowNumbers = Fals
.FillAdjacentFormulas = Fals
.RefreshOnFileOpen = Fals
.HasAutoFormat = Tru
.BackgroundQuery = Tru
.TablesOnlyFromHTML = Tru
.Refresh BackgroundQuery:=Fals
.SavePassword = Fals
.SaveData = Tru
End Wit

sheets("Sheet2").selec

varconnection = "http://www.yahoo.com

With ActiveSheet.QueryTables.Add(Connection:=
"URL;" & varconnection, Destination:=Range(
"A1")
.FieldNames = Fals
.RefreshStyle = xlInsertDeleteCell
.RowNumbers = Fals
.FillAdjacentFormulas = Fals
.RefreshOnFileOpen = Fals
.HasAutoFormat = Tru
.BackgroundQuery = Tru
.TablesOnlyFromHTML = Tru
.Refresh BackgroundQuery:=Fals
.SavePassword = Fals
.SaveData = Tru
End Wit
 
S

SmilingPolitely

what are you trying to get from Yahoo!

if stock data please send email to

spreadsheethelp
at
iinet
dot
net
dot
au

and I might have something for you.....
 
D

Don Guillett

I just tested your exact code in xl2002 and also in xl97. It worked just
fine.

However, I question what you are really trying to do since it would not be
the best to create a separate query sheet for each query needed and . It
would be better to use one query that you modify. I write stock retrival,
manipulation programs for customers all the time.

BTW. It is also not necessary to select the sheet first when you do it like
this.

With Sheets("sheet1").QueryTables.Add(Connection:= _
"URL;" & varconnection, Destination:=Sheets("sheet1").Range("A1"))
--
Don Guillett
SalesAid Software
(e-mail address removed)
bdm3 said:
Hi,

I am trying to write a web query in vba using the following code:

---------------------------------------

sheets("Sheet1").select

varconnection = "http://www.yahoo.com"

With ActiveSheet.QueryTables.Add(Connection:= _
"URL;" & varconnection, Destination:=Range( _
"A1"))
.FieldNames = False
.RefreshStyle = xlInsertDeleteCells
.RowNumbers = False
.FillAdjacentFormulas = False
.RefreshOnFileOpen = False
.HasAutoFormat = True
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.SavePassword = False
.SaveData = True
End With

sheets("Sheet2").select

varconnection = "http://www.yahoo.com"

With ActiveSheet.QueryTables.Add(Connection:= _
"URL;" & varconnection, Destination:=Range( _
"A1"))
.FieldNames = False
.RefreshStyle = xlInsertDeleteCells
.RowNumbers = False
.FillAdjacentFormulas = False
.RefreshOnFileOpen = False
.HasAutoFormat = True
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.SavePassword = False
.SaveData = True
End With
errors out with 1004 - Application-defined or object-defined error. What I
can't figure out is this: This code works on my friend's laptop but not
mine. This code works on my laptop when I connect to the internet via dial
up, but not when I am on cable. I can't figure out why this would work in
some of these situations but not others. Any help anyone can offer would be
a life saver!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top