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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

web queries in excel - Run-time error '-2147024809 (80070057)' 1

Status
Not open for further replies.

Aubs010

Technical User
Apr 4, 2003
306
GB
I'm using web queries in excel.


The following is the code I use to gather the info from "[ignore][/ignore]"

Code:
ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
ActiveWorkbook.ActiveSheet.Name = "Data Collection"
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;[URL unfurl="true"]http://somewebaddress/MyInfo?Aubs"[/URL] _
        , Destination:=Range("A1"))
        .Name = "MyInfo?Aubs"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlSpecifiedTables
        .WebFormatting = xlWebFormattingNone
        .WebTables = "1"
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
ActiveWorkbook.Sheets("List").Select

If I have a button on the sheet called "List", and call the above code, I get:
Code:
Run-time error '-2147024809 (80070057)':

The destination range is not on the same worksheet that the query table is being created on.

I have created a macro, using Excel's built in writer, and this is the code it provides, which works fine!

Code:
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 25/11/2003 by Aubs
'

'
    ActiveWorkbook.Worksheets.Add
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;[URL unfurl="true"]http://setiathome2.ssl.berkeley.edu/fcgi-bin/fcgi?email=test@test.com&cmd=user_stats_new"[/URL] _
        , Destination:=Range("A1"))
        .Name = "fcgi?email=test@test.com&cmd=user_stats_new"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlSpecifiedTables
        .WebFormatting = xlWebFormattingNone
        .WebTables = "1"
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
End Sub

Any help would be greatly appreciated.

Aubs
 
try this:

dim newSht as worksheet
set NewSht = ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
NewSht.Name = "Data Collection"
With NewSht.QueryTables.Add(Connection:= _
"URL; _
, Destination:=NewSht.Range("A1"))

Rgds, Geoff
[blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
 
Thanks for the code Geoff,

Unfortunately... guess... yup, the same error!

It seems as if the sheet calling has to be the same sheet as the table and result...

ooer, wait!

I got it... has to be:
Code:
Dim NS As Worksheet
Set NS = ActiveWorkbook.Sheets.Add
NS.Name = "Data Collection"
    With NS.QueryTables.Add(Connection:= _
        "URL;[URL unfurl="true"]http://http://somewebaddress/MyInfo?Aubs"[/URL] _
        , Destination:=
NS.
Code:
Range("A1"))

Thanks for your help Geogg, much appreciated... a
star.gif
for you me thinks for the inspiration and very near answer!

Regards,

Aubs
 
um - don't wanna be a killjoy here but isn't that exactly what I posted ??

Rgds, Geoff
[blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
 
Um, yeah, sorry, it was!!!!

I didn't notice that little bit!! - Saw the first and thought that was the only mod you made... Will teach me to look more closely!

Thanks again [2thumbsup]



Aubs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top