Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tom Tom is offline
external usenet poster
 
Posts: 38
Default QueryDef; Error 1004

Hello,

I often import stock quotes using the QueryDef method without any problems.
But for some reasons I'm not able to import certain stocks quotes. Sometimes
the macro works, sometimes not (Error 1004) and I don't know why. I created
the following example:

Sub ImportData()
Dim ws As Worksheet
Dim qry As QueryTable
Dim n As Name
Dim sURL As String

sURL = "http://www.swissquote.ch/fcgi-bin/stockfquote?symbols=ALFGR"

Set ws = ThisWorkbook.Worksheets(1)

'delete old data
ws.Cells.Delete
For Each qry In ws.QueryTables
qry.Delete
Next qry
For Each n In ThisWorkbook.Names
n.Delete
Next n

'import
With ws.QueryTables.Add(Connection:="URL;" & sURL,
Destination:=ws.Range("$A$1"))
.Name = "stockfquote?symbols=ALFGR"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub


Has anybody an idea why this script generates the error 1004?

Tom

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default QueryDef; Error 1004

I just ran your code in xl2003, as written, and except for the fact that
there are unnecessary lines, it worked many times without any problem. I do
this sort of thing for clients all the time. You would need to make sure
that the url recognizes the symbol as you have it. Do they have a symbol
lookup?

Surely you are not creating a separate query for each symbol in a portfolio.
You should be able to have a list do with a loop or even all with ONE fetch.
Send an email to my private address and I'll send a file that uses Yahoo but
did not know this symbol.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Tom" wrote in message
...
Hello,

I often import stock quotes using the QueryDef method without any
problems. But for some reasons I'm not able to import certain stocks
quotes. Sometimes the macro works, sometimes not (Error 1004) and I don't
know why. I created the following example:

Sub ImportData()
Dim ws As Worksheet
Dim qry As QueryTable
Dim n As Name
Dim sURL As String

sURL = "http://www.swissquote.ch/fcgi-bin/stockfquote?symbols=ALFGR"

Set ws = ThisWorkbook.Worksheets(1)

'delete old data
ws.Cells.Delete
For Each qry In ws.QueryTables
qry.Delete
Next qry
For Each n In ThisWorkbook.Names
n.Delete
Next n

'import
With ws.QueryTables.Add(Connection:="URL;" & sURL,
Destination:=ws.Range("$A$1"))
.Name = "stockfquote?symbols=ALFGR"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub


Has anybody an idea why this script generates the error 1004?

Tom


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
run time error 1004 general odbc error excel 2003 vba Mentos Excel Programming 5 January 24th 11 02:56 PM
Error handling error # 1004 Run-time error [email protected] Excel Programming 3 May 20th 08 02:23 PM
runtime error '1004' application or object defined error. Please help deej Excel Programming 0 August 1st 07 09:26 AM
Run Time 1004 Error: Application or Object Difine Error BEEJAY Excel Programming 0 October 17th 06 10:45 PM
run-time error '1004': Application-defined or object-deifined error [email protected] Excel Programming 5 August 10th 05 09:39 PM


All times are GMT +1. The time now is 03:45 AM.

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

About Us

"It's about Microsoft Excel"