View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Pause until MSNSTockQuote runs

Hi Ron,

I know I can do something like a while/wend loop, but I don't know what to
use
as a flag for this routine.


In a light test the following seemed to work for me.

Sub test()
' requires the free MSNStockQuote addin
Dim bGot As Boolean
Dim t As Single
Dim timeOut As Single
Dim aa, bb

timeOut = 3 ' seconds
t = Timer
With Range("A1")
.ClearContents
.FormulaR1C1 = "=MSNStockQuote(""msft"",""Last"",""US"")"
aa = .Value
If IsError(aa) Then aa = .Text
bGot = False
Do
bb = .Value
If VarType(bb) < vbError Then
If Len(bb) Then bGot = IsNumeric(bb)
End If
Loop Until bGot Or (Timer - t timeOut)

If IsError(bb) Then bb = .Text & " " & CStr(bb) ' eg #N/A or #VALUE
End With

MsgBox "before-loop: " & aa & vbCr & _
"after - loop : " & bb
End Sub


I notice after a (very) long time MSNStockQuote shows its own timed-out msg
if say a non valid ticker is used.

For more control perhaps try Web-Query

Regards,
Peter T

"Ron Rosenfeld" wrote in message
...
As part of a macro, I am modifying several worksheets and the modification
includes adding a column of about 30 rows with the function of the form:

=MSNStockQuote($A6,"Last","US")

This command fetches data from the Internet.
After it runs, other cells are calculated.

I would like to know when the function has obtained the data, in all of
the
rows, so that I can then "autosize" the columns. (If I don't wait, the
columns
will be too small).

I know I can do something like a while/wend loop, but I don't know what to
use
as a flag for this routine.

I could, for example, use the presence of real data in the bottommost row,
but
if that happens to be a quote for which there happens to be no data; or if
the
server is down; or if the macro is being run during the "5-minute" timeout
of
the function, then my macro will "hang".

Any thoughts would be appreciated.

Thanks.
--ron