View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default Pause until MSNSTockQuote runs

On Sat, 27 Dec 2008 11:52:36 -0000, "Peter T" <peter_t@discussions wrote:

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


Thanks. I'll give that idea a try. I appreciate that.

I suppose I could just check all the cells until data has been returned, and
perhaps set a maximum time. I was hoping there might be some value that might
get returned after MSNStockQuote has finished running.
--ron