ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   On Error GoTo skip needs help (https://www.excelbanter.com/excel-discussion-misc-queries/84831-error-goto-skip-needs-help.html)

dan

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



Jim Rech

On Error GoTo skip needs help
 
I'd guess Windows("ABC").Activate is failing. How about
Sheets("Sheet1").Activate instead?

--
Jim
"dan" 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
|
|



dan

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" wrote in message
...
I'd guess Windows("ABC").Activate is failing. How about
Sheets("Sheet1").Activate instead?

--
Jim
"dan" 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
|
|






All times are GMT +1. The time now is 07:42 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com