+ Reply to Thread
Results 1 to 3 of 3

On Error GoTo skip needs help

  1. #1
    dan
    Guest

    On Error GoTo skip needs help

    "Subscript out of range" appeared when a non existant file was entered,
    and the execution was aborted.
    Can you help me to continue the execution?

    Sub Analyse()
    Dim Ans As Variant
    Dim filename As String
    Sheets("Sheet1").Select
    Ans = InputBox(prompt:="Enter the data file name. ")
    If Ans = "" Then Exit Sub
    filename = Ans & ".csv"
    On Error GoTo skip
    Workbooks.Open filename:="F:\Cabinet1\" & filename, UpdateLinks:=0
    ' Main analysis body here
    Exit Sub
    skip:
    Windows("ABC").Activate
    Sheets("Sheet1").Range("H1") = Ans & " file does not exist!"
    End Sub



  2. #2
    Jim Rech
    Guest

    Re: On Error GoTo skip needs help

    I'd guess Windows("ABC").Activate is failing. How about
    Sheets("Sheet1").Activate instead?

    --
    Jim
    "dan" <[email protected]> wrote in message
    news:IU63g.200$ud.152@trndny03...
    | "Subscript out of range" appeared when a non existant file was entered,
    | and the execution was aborted.
    | Can you help me to continue the execution?
    |
    | Sub Analyse()
    | Dim Ans As Variant
    | Dim filename As String
    | Sheets("Sheet1").Select
    | Ans = InputBox(prompt:="Enter the data file name. ")
    | If Ans = "" Then Exit Sub
    | filename = Ans & ".csv"
    | On Error GoTo skip
    | Workbooks.Open filename:="F:\Cabinet1\" & filename, UpdateLinks:=0
    | ' Main analysis body here
    | Exit Sub
    | skip:
    | Windows("ABC").Activate
    | Sheets("Sheet1").Range("H1") = Ans & " file does not exist!"
    | End Sub
    |
    |



  3. #3
    dan
    Guest

    Re: On Error GoTo skip needs help

    Hi, Jim
    You are right. It should be Windows("ABC.xls").Activate
    Thank you for pointing out.

    "Jim Rech" <[email protected]> wrote in message
    news:[email protected]...
    > I'd guess Windows("ABC").Activate is failing. How about
    > Sheets("Sheet1").Activate instead?
    >
    > --
    > Jim
    > "dan" <[email protected]> wrote in message
    > news:IU63g.200$ud.152@trndny03...
    > | "Subscript out of range" appeared when a non existant file was entered,
    > | and the execution was aborted.
    > | Can you help me to continue the execution?
    > |
    > | Sub Analyse()
    > | Dim Ans As Variant
    > | Dim filename As String
    > | Sheets("Sheet1").Select
    > | Ans = InputBox(prompt:="Enter the data file name. ")
    > | If Ans = "" Then Exit Sub
    > | filename = Ans & ".csv"
    > | On Error GoTo skip
    > | Workbooks.Open filename:="F:\Cabinet1\" & filename,
    > UpdateLinks:=0
    > | ' Main analysis body here
    > | Exit Sub
    > | skip:
    > | Windows("ABC").Activate
    > | Sheets("Sheet1").Range("H1") = Ans & " file does not exist!"
    > | End Sub
    > |
    > |
    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1