How to cancel "Contacting Server" Alert using VBA

DLW1

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

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Has anyone come up with an answer to this?

I have a similar problem. It doesn't hang, but the dialogue box still comes up when I don't want it to. This happens when using:

Code:
Workbooks.Open Filename:=URL

Where the URL is just a web address that downloads a csv file.

I was thinking of using Application.Dialogs, but couldn't find the appropriate "builtindialog" to control.

Thanks
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,911
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top