Consulting

Results 1 to 4 of 4

Thread: Solved: File not Foud on web Error Handeling

  1. #1
    VBAX Regular
    Joined
    Nov 2005
    Posts
    39
    Location

    Solved: File not Foud on web Error Handeling

    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:

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

    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.

    Thanks!

  2. #2
    VBAX Expert
    Joined
    Jul 2004
    Location
    Wilmington, DE
    Posts
    600
    Location
    Quote Originally Posted by GMan
    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:

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

    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.

    Thanks!
    VBA allows for decent error handling.

    [VBA]
    Sub Test()

    'do something
    On Error Goto MyErrHandler

    'do some ore stuff

    Exit Sub
    MyErrHandler:
    MsgBox "File not found. Sorry!"
    End Sub
    [/VBA]

  3. #3
    VBAX Regular
    Joined
    Nov 2005
    Posts
    39
    Location
    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.

  4. #4
    VBAX Expert
    Joined
    Jul 2004
    Location
    Wilmington, DE
    Posts
    600
    Location
    Glad to help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •