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 click cancel 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
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