#1   Report Post  
 
Posts: n/a
Default Web query again

Hello,

I looked on MSDN about web queries with VBA. But the code I took from
there doesn't work.

Dim BaseURL As String
BaseURL = "some URL"
Const StartDate As Date = #11/2/2004#, EndDate As Date = #4/20/2005#

Dim d As Date
For d = StartDate To EndDate
Dim newSheet As New Excel.Worksheet

Set newSheet = Worksheets.Add
With newSheet
.Name = Replace(CStr(d), "/", ".")
Call .Activate
End With

'MsgBox ("URL;" & BaseURL)

'Next line gives an error
'Run-time error '5':
'Invalid procedure call or argument

With ActiveSheet.QueryTables.Add("URL;" & BaseURL, Range("A1"))
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.SaveData = True
End With

Worksheets(Replace(CStr(d), "/", ".")).Move
After:=Worksheets(Worksheets.Count)
Next d

The line that I get the error is noted above. The line looks correct to
me. Can someone help?

Thanks,
Andrew

  #2   Report Post  
moi
 
Posts: n/a
Default

maybe this?

With ActiveSheet
.QueryTables.Add "URL;" & BaseURL, Range("A1")
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.SaveData = True
End With



schreef in bericht
oups.com...
Hello,

I looked on MSDN about web queries with VBA. But the code I took from
there doesn't work.

Dim BaseURL As String
BaseURL = "some URL"
Const StartDate As Date = #11/2/2004#, EndDate As Date = #4/20/2005#

Dim d As Date
For d = StartDate To EndDate
Dim newSheet As New Excel.Worksheet

Set newSheet = Worksheets.Add
With newSheet
.Name = Replace(CStr(d), "/", ".")
Call .Activate
End With

'MsgBox ("URL;" & BaseURL)

'Next line gives an error
'Run-time error '5':
'Invalid procedure call or argument

With ActiveSheet.QueryTables.Add("URL;" & BaseURL, Range("A1"))
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.SaveData = True
End With

Worksheets(Replace(CStr(d), "/", ".")).Move
After:=Worksheets(Worksheets.Count)
Next d

The line that I get the error is noted above. The line looks correct to
me. Can someone help?

Thanks,
Andrew



  #3   Report Post  
Andrew Clark
 
Posts: n/a
Default

"moi" wrote in news:d4dftl$7jf$1
@reader13.wxs.nl:

maybe this?

With ActiveSheet
.QueryTables.Add "URL;" & BaseURL, Range("A1")
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.SaveData = True
End With







I figured it out. My code needed to be in 'ThisWorkbook'. Once I moved it
there, everything worked A-OK. Previously, I had it in 'Sheet1'.

Andrew
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Query -- Data Type Mismatch StephenP Excel Discussion (Misc queries) 0 April 14th 05 07:05 PM
Excel2000 ODBC query oddity Arvi Laanemets Excel Discussion (Misc queries) 0 March 10th 05 06:35 AM
Query of External Data Excel GuRu Excel Discussion (Misc queries) 2 January 3rd 05 07:43 PM
Microsoft Query Help Patti Excel Worksheet Functions 4 December 25th 04 09:54 AM
How to use a Access Query that as a parameter into Excel database query Karen Middleton Excel Discussion (Misc queries) 1 December 13th 04 07:54 PM


All times are GMT +1. The time now is 11:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"