Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a webquery table

Status
Not open for further replies.

sandoztek

Programmer
Aug 20, 2008
27
FR
In a piece of code using web queries I normally use the F1 sheet
But when I started a similar code using another F2 sheet I have an error I do not understand:
Please explain why the first set works and the second one doesn't,
I get
"argument or procedure call incorrect (error 5)"
Both sheets do exist

Set qt =Worksheets("F1").QueryTables.Add(Connection:="URL; Destination:=Range("A1"))

Set qt = Worksheets("F2").QueryTables.Add(Connection:="URL; Destination:=Range("A1"))
 
Hi,

Explicitly reference your sheet for ALL objects...
Code:
with Worksheets("F1")
  Set qt =.QueryTables.Add(Connection:="URL;[URL unfurl="true"]http://www.racingpost.co.uk",[/URL] Destination:=.Range("A1")) 
end with

with Worksheets("F2")
 Set qt = .QueryTables.Add(Connection:="URL;[URL unfurl="true"]http://www.racingpost.co.uk",[/URL] Destination:=.Range("A1"))
end with


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Ok, fine now, I'll try not to forget the advice.
It's a subtelty I haven't seen documented yet...
Thank you !
 




You are on sheet whatever.

You ADD a querytable object, using some OTHER sheet reference, but make the destination object a range without a sheet reference, resulting in Excel thinking that the destination is on sheet whatever, not sheet OTHER -- TILT!!!

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Capito, the problem was the (ambiguous)Destination.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top