[英]VBA - error handing for non-existent web resource (Yahoo finance)
My macro generates yahoo ticker download URL's for specific companies. 我的宏会为特定公司生成Yahoo代码下载URL。 I generate 3 URL's per ticker, each having a different date segment for the data download.
我为每个代码生成3个URL,每个URL都有不同的日期段用于数据下载。
The problem that I have, is that data does not exist for some of the dates, hence an error is returned from Yahoo which causes my Macro to crash. 我的问题是某些日期不存在数据,因此从Yahoo返回了一个错误,导致我的Macro崩溃。
I've attempted the following with a GOTO label:- 我尝试使用GOTO标签进行以下操作:-
On Error GoTo error_handler
Workbooks.Open Filename:=("http://chart.finance.yahoo.com/table.csv?s=FAN.L&a=2&b=04&c=2014&d=2&e=21&f=2014&g=d&ignore=.csv")
however this does not work, it does not GOTO the label. 但是,这不起作用,它不会转到标签。
Any ideas would be greatly appreciated. 任何想法将不胜感激。
Here is some example of error handling. 这是错误处理的一些示例。 Replace your code with the
Debug.print 5/0
and it should work. 将代码替换为
Debug.print 5/0
,它应该可以工作。
Public Sub ErrorHandlingExample()
On Error GoTo ErrorHandlingExample_Error
Debug.Print 5 / 0
On Error GoTo 0
Debug.Print "No error"
Exit Sub
ErrorHandlingExample_Error:
Debug.Print "Error was found - " & Err.Description
End Sub
Try this: 尝试这个:
On Error Resume Next
Workbooks.Open Filename:=("http://chart.finance.yahoo.com/table.csv?s=FAN.L&a=2&b=04&c=2014&d=2&e=21&f=2014&g=d&ignore=.csv")
On Error GoTo error_handler
The On Error Resume Next will allow it to the skip ahead. On Error Resume Next将允许其向前跳过。
Download the file with seperate error handling and then if-check 下载具有单独错误处理的文件,然后进行if-check
If Dir(MyFileName) <> "" Then
Workbooks.Open Filename:="C:\123.xls"
Else
MsgBox "Spreadsheet could not be found in C:\", vbCritical + vbOKOnly, "File not found"
End If
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.