Terminating IE connection when server not responding

DLW1

New Member
Joined
Mar 22, 2011
Messages
3
<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>
 

Some videos you may like

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Watch MrExcel Video

Forum statistics

Threads
1,109,360
Messages
5,528,243
Members
409,809
Latest member
VICKRAM

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top