<TABLE class=tborder id=post2656268 cellSpacing=0 cellPadding=6 width="100%" align=center border=0><TBODY><TR vAlign=top><TD class=alt1 id=td_post_2656268 style="BORDER-RIGHT: #ffffff 1px solid">I am contacting the yahoo finance server to download a large group of historical stock quotes using VBA. Everything typically works fine but I occasionally get a message alert that says "Contacting Server" or "downloading". Once this happens for an extended time I lose control and the VBA code hangs. I must maually hit the escape key or cancel key to continue the program. How do I detect this alert automatically in VBA and terminate the internet connection so I can retry again? The application.displayalerts=False command does not suppress it. Thanks very much to anyone that can help. Here is the relevent part of my code:
For N = 1 To StockNum
Workbooks(SPfile).Activate
Name = Range("A" & N).Value
Symb = Range("B" & N).Value
On Error GoTo Err_Handler
Application.DisplayAlerts = False
Workbooks.Open ("http://ichart.finance.yahoo.com/table.csv?s=" & Symb & "&d=" & Month & "&e=" & Day & "&f=" & Year & "&g=d&a=9&b=6&c=2007&ignore=.csv") 'downloads yahoo data. This is the statement that sometimes hangs
Workbooks("table").Activate
Application.DisplayAlerts = True
Range("B2.G2").Activate 'Copies Daily table data into Master Stock File starting at row 3
Selection.Copy
Workbooks("MasterStockFile2").Worksheets("Daily").Activate
Range("c" & (N + 2)).Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("a" & (N + 2)) = Name
Range("b" & (N + 2)) = Symb
Next N
<!-- / message --></TD></TR><TR><TD class=alt2 style="BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #ffffff 0px solid; BORDER-LEFT: #ffffff 1px solid; BORDER-BOTTOM: #ffffff 1px solid">
</TD><TD class=alt1 style="BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #ffffff 0px solid; BORDER-LEFT: #ffffff 0px solid; BORDER-BOTTOM: #ffffff 1px solid" align=right><!-- controls --></TD></TR></TBODY></TABLE>
For N = 1 To StockNum
Workbooks(SPfile).Activate
Name = Range("A" & N).Value
Symb = Range("B" & N).Value
On Error GoTo Err_Handler
Application.DisplayAlerts = False
Workbooks.Open ("http://ichart.finance.yahoo.com/table.csv?s=" & Symb & "&d=" & Month & "&e=" & Day & "&f=" & Year & "&g=d&a=9&b=6&c=2007&ignore=.csv") 'downloads yahoo data. This is the statement that sometimes hangs
Workbooks("table").Activate
Application.DisplayAlerts = True
Range("B2.G2").Activate 'Copies Daily table data into Master Stock File starting at row 3
Selection.Copy
Workbooks("MasterStockFile2").Worksheets("Daily").Activate
Range("c" & (N + 2)).Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("a" & (N + 2)) = Name
Range("b" & (N + 2)) = Symb
Next N
<!-- / message --></TD></TR><TR><TD class=alt2 style="BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #ffffff 0px solid; BORDER-LEFT: #ffffff 1px solid; BORDER-BOTTOM: #ffffff 1px solid">