PDA

View Full Version : Solved: File not Foud on web Error Handeling



GMan
12-09-2005, 10:01 AM
I have a VBA script that is pulling a file from a Web site into Excel. Every once in a while the file being requested is not found and the VBA gets an error the the file can not be found. After clicking "OK", I receive an Microsoft VB error ('1004') stating again the file can not be access. But this message comes with the "END", "DEBUG", and "HELP" buttons.

Is there a more graceful way to handle this error. I can't use a DIR command to check for the file first because the I am not using a file path. The VBA Command to open the file is below:

Workbooks.OpenText Filename:=http:"//website.com/report/date12092005.csv"

Any help would be greatly appreciated. Being a beginner with VBA, I have not figured out all the basics with error handling yet as well as other basics I seem to get educated on with each issue I find myself facing.:banghead:

Thanks!

matthewspatrick
12-09-2005, 11:48 AM
I have a VBA script that is pulling a file from a Web site into Excel. Every once in a while the file being requested is not found and the VBA gets an error the the file can not be found. After clicking "OK", I receive an Microsoft VB error ('1004') stating again the file can not be access. But this message comes with the "END", "DEBUG", and "HELP" buttons.

Is there a more graceful way to handle this error. I can't use a DIR command to check for the file first because the I am not using a file path. The VBA Command to open the file is below:

Workbooks.OpenText Filename:=http:"//website.com/report/date12092005.csv"

Any help would be greatly appreciated. Being a beginner with VBA, I have not figured out all the basics with error handling yet as well as other basics I seem to get educated on with each issue I find myself facing.:banghead:

Thanks!

VBA allows for decent error handling.


Sub Test()

'do something
On Error Goto MyErrHandler

'do some ore stuff


Exit Sub
MyErrHandler:

MsgBox "File not found. Sorry!"

End Sub

GMan
12-09-2005, 12:11 PM
This is almost embarrassing. I hate when old knowledge from other programming languages get in the way of me figuring out easy problems. I have seen the "ON ERROR" logic in other examples but neglected to see that the "ON ERROR" comes BEFORE the error occurance. I am used to checking for errors after the statements and therefore "ON ERROR" didn't work for me when I attempted it originally.

Thanks for the beginners lesson. :thumb

matthewspatrick
12-09-2005, 12:15 PM
Glad to help :beerchug: